Skip to content

Commit

Permalink
Replace deprecated cgi module with multipart
Browse files Browse the repository at this point in the history
  • Loading branch information
tw4l committed Oct 28, 2024
1 parent 3df3bbc commit 7a602f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cdxj_indexer/postquery.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def run_tests(self):
# temp fix for requests
"idna<3.0",
"py3amf",
"multipart",
],
zip_safe=True,
entry_points="""
Expand Down

0 comments on commit 7a602f2

Please sign in to comment.