diff --git a/cdxj_indexer/postquery.py b/cdxj_indexer/postquery.py index aafb110..8e35719 100644 --- a/cdxj_indexer/postquery.py +++ b/cdxj_indexer/postquery.py @@ -1,14 +1,16 @@ -from warcio.utils import to_native_str +import base64 +import json +import sys from urllib.parse import unquote_plus, urlencode from io import BytesIO +from multipart import parse_options_header, MultipartParser +from warcio.utils import to_native_str + from cdxj_indexer.amf import amf_parse -import base64 -import cgi -import json -import sys + MAX_QUERY_LENGTH = 4096 @@ -101,17 +103,17 @@ def handle_binary(query_data): args = dict(fp=BytesIO(query_data), environ=env, keep_blank_values=True) - args["encoding"] = "utf-8" - try: - data = cgi.FieldStorage(**args) + _, params = parse_options_header(mime) + boundary = params["boundary"] + parser = MultipartParser(stream, boundary, charset="utf8") except ValueError: # Content-Type multipart/form-data may lack "boundary" info query = handle_binary(query_data) else: values = [] - for item in data.list: - values.append((item.name, item.value)) + for part in parser: + values.append((part.name, part.value)) query = urlencode(values, True) diff --git a/setup.py b/setup.py index 9679105..0220633 100755 --- a/setup.py +++ b/setup.py @@ -51,6 +51,7 @@ def run_tests(self): # temp fix for requests "idna<3.0", "py3amf", + "multipart", ], zip_safe=True, entry_points="""