Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cgi.parse_header() with custom function for Python 3.13 compat #713

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spyne/protocol/soap/mime.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def collapse_swa(ctx, content_type, ns_soap_env):
http://www.w3.org/Submission/soap11mtom10/

:param content_type: value of the Content-Type header field, parsed by
cgi.parse_header() function
spyne.util.http.parse_content_type_header() function
:param ctx: request context
"""

Expand Down
5 changes: 2 additions & 3 deletions spyne/protocol/soap/soap11.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
logger = logging.getLogger(__name__)
logger_invalid = logging.getLogger(__name__ + ".invalid")

import cgi

from itertools import chain

import spyne.const.xml as ns
Expand All @@ -50,6 +48,7 @@

from spyne import BODY_STYLE_WRAPPED
from spyne.util import six
from spyne.util.http import parse_content_type_header
from spyne.const.xml import DEFAULT_NS
from spyne.const.http import HTTP_405, HTTP_500
from spyne.error import RequestNotAllowed
Expand Down Expand Up @@ -197,7 +196,7 @@ def create_in_document(self, ctx, charset=None):
"You must issue a POST request with the Content-Type "
"header properly set.")

content_type = cgi.parse_header(content_type)
content_type = parse_content_type_header(content_type)
ctx.in_string = collapse_swa(ctx, content_type, self.ns_soap_env)

ctx.in_document = _parse_xml_string(ctx.in_string,
Expand Down
6 changes: 3 additions & 3 deletions spyne/server/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import logging
logger = logging.getLogger(__name__)

import cgi
import threading

from inspect import isgenerator
Expand All @@ -44,6 +43,7 @@
from spyne.server.http import HttpBase, HttpMethodContext, HttpTransportContext
from spyne.util.odict import odict
from spyne.util.address import address_parser
from spyne.util.http import parse_content_type_header

from spyne.const.ansi_color import LIGHT_GREEN
from spyne.const.ansi_color import END_COLOR
Expand Down Expand Up @@ -527,9 +527,9 @@ def __reconstruct_wsgi_request(self, http_env):
charset = None
if content_type is not None:
# fyi, here's what the parse_header function returns:
# >>> import cgi; cgi.parse_header("text/xml; charset=utf-8")
# >>> parse_content_type_header("text/xml; charset=utf-8")
# ('text/xml', {'charset': 'utf-8'})
content_type = cgi.parse_header(content_type)
content_type = parse_content_type_header(content_type)
charset = content_type[1].get('charset', None)

return self.__wsgi_input_to_iterable(http_env), charset
Expand Down
6 changes: 6 additions & 0 deletions spyne/util/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import sys
import time

from email.message import EmailMessage
from time import strftime
from time import gmtime
from collections import deque
Expand Down Expand Up @@ -72,3 +73,8 @@ def generate_cookie(k, v, max_age=None, domain=None, path=None,
retval.append("Secure")

return '; '.join(retval)

def parse_content_type_header(h):
msg = EmailMessage()
msg['content-type'] = h
return msg.get_content_type(), msg['content-type'].params