Skip to content

Commit 556e2d8

Browse files
authored
remove dependence on cgi module (#344)
1 parent 606763c commit 556e2d8

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

tests/mockduo.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# mockduo.py
99
#
1010

11-
import cgi
1211
import json
1312
from http.server import BaseHTTPRequestHandler, HTTPServer
1413
import email.utils
@@ -135,14 +134,10 @@ def _verify_sig(self):
135134

136135
def _get_args(self):
137136
if self.method == "POST":
138-
env = {
139-
"REQUEST_METHOD": "POST",
140-
"CONTENT_TYPE": self.headers["Content-Type"],
141-
}
142-
fs = cgi.FieldStorage(fp=self.rfile, headers=self.headers, environ=env)
143-
args = {}
144-
for k in fs.keys():
145-
args[k] = fs[k].value
137+
# Parse application/x-www-form-urlencoded POST body
138+
content_length = int(self.headers.get("Content-Length", "0") or 0)
139+
body = self.rfile.read(content_length).decode("utf-8") if content_length > 0 else ""
140+
args = dict(urllib.parse.parse_qsl(body, keep_blank_values=True))
146141
else:
147142
args = dict(urllib.parse.parse_qsl(self.qs))
148143
print("got {0} {1} args: {2}".format(self.method, self.path, args))

0 commit comments

Comments
 (0)