Skip to content

Commit

Permalink
Fix python3 compatibility when parsing request body
Browse files Browse the repository at this point in the history
On python3 the QueryStringParser can't handle bytestrings. Restore
previous (probably broken) behavior on Python3. Feel free to further fix
this.
  • Loading branch information
spaceone committed Jan 9, 2017
1 parent 0886e9a commit aceb480
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion circuits/web/processors.py
@@ -1,6 +1,7 @@
import re
from cgi import parse_header

from circuits.six import PY3
from .headers import HeaderElement
from .parsers import MultipartParser
from .parsers import QueryStringParser
Expand Down Expand Up @@ -37,9 +38,11 @@ def process_multipart(request, params):
def process_urlencoded(request, params, encoding="utf-8"):
params.update(QueryStringParser(request.qs).result)
body = request.body.getvalue()
if PY3:
body = body.decode(self.encoding)
result = QueryStringParser(body).result
for key, value in result.items():
params[key.decode(encoding)] = _decode_value(value, encoding)
params[_decode_value(key, encoding)] = _decode_value(value, encoding)


def _decode_value(value, encoding):
Expand Down

0 comments on commit aceb480

Please sign in to comment.