summaryrefslogtreecommitdiffstats
path: root/Lib/cgi.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2013-01-23 11:00:26 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2013-01-23 11:00:26 (GMT)
commitc1a7c565aaf1dfa573337bbc9a5222097252cf3b (patch)
tree6c1f886edf62c6c31157a7ef397a14295a2f7d1b /Lib/cgi.py
parent9427b0313346fc629d9b3f5e0134fbacb8533c06 (diff)
parent6b102f251f086feb058ed9aac8072bbafe362372 (diff)
downloadcpython-c1a7c565aaf1dfa573337bbc9a5222097252cf3b.zip
cpython-c1a7c565aaf1dfa573337bbc9a5222097252cf3b.tar.gz
cpython-c1a7c565aaf1dfa573337bbc9a5222097252cf3b.tar.bz2
merge from 3.2
Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and bytes data. Patch by Jonas Wagner.
Diffstat (limited to 'Lib/cgi.py')
-rwxr-xr-xLib/cgi.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index e964f0c..96b1f57 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -223,17 +223,17 @@ def parse_multipart(fp, pdict):
"""
import http.client
- boundary = ""
+ boundary = b""
if 'boundary' in pdict:
boundary = pdict['boundary']
if not valid_boundary(boundary):
raise ValueError('Invalid boundary in multipart form: %r'
% (boundary,))
- nextpart = "--" + boundary
- lastpart = "--" + boundary + "--"
+ nextpart = b"--" + boundary
+ lastpart = b"--" + boundary + b"--"
partdict = {}
- terminator = ""
+ terminator = b""
while terminator != lastpart:
bytes = -1
@@ -252,7 +252,7 @@ def parse_multipart(fp, pdict):
raise ValueError('Maximum content length exceeded')
data = fp.read(bytes)
else:
- data = ""
+ data = b""
# Read lines until end of part.
lines = []
while 1:
@@ -260,7 +260,7 @@ def parse_multipart(fp, pdict):
if not line:
terminator = lastpart # End outer loop
break
- if line.startswith("--"):
+ if line.startswith(b"--"):
terminator = line.rstrip()
if terminator in (nextpart, lastpart):
break
@@ -272,12 +272,12 @@ def parse_multipart(fp, pdict):
if lines:
# Strip final line terminator
line = lines[-1]
- if line[-2:] == "\r\n":
+ if line[-2:] == b"\r\n":
line = line[:-2]
- elif line[-1:] == "\n":
+ elif line[-1:] == b"\n":
line = line[:-1]
lines[-1] = line
- data = "".join(lines)
+ data = b"".join(lines)
line = headers['content-disposition']
if not line:
continue