1
0
mirror of https://github.com/django/django.git synced 2025-10-31 01:25:32 +00:00

[py3] Fixed Python 3 compatibility of http handling

* Using str() when Python 2 expects bytes and Python 3 Unicode
* Fixed reraise-ing syntax
* Fixed slicing of byte strings
This commit is contained in:
Claude Paroz
2012-08-11 14:44:34 +02:00
parent 22527a821b
commit f10a1b0641
2 changed files with 9 additions and 7 deletions

View File

@@ -507,9 +507,11 @@ class BoundaryIter(object):
end = index
next = index + len(self._boundary)
# backup over CRLF
if data[max(0,end-1)] == b'\n':
last = max(0, end-1)
if data[last:last+1] == b'\n':
end -= 1
if data[max(0,end-1)] == b'\r':
last = max(0, end-1)
if data[last:last+1] == b'\r':
end -= 1
return end, next
@@ -613,7 +615,7 @@ def parse_header(line):
if i >= 0:
name = p[:i].strip().lower().decode('ascii')
value = p[i+1:].strip()
if len(value) >= 2 and value[0] == value[-1] == b'"':
if len(value) >= 2 and value[:1] == value[-1:] == b'"':
value = value[1:-1]
value = value.replace(b'\\\\', b'\\').replace(b'\\"', b'"')
pdict[name] = value