Source code for wheezy.http.parse
""" ``parser`` module.
"""
from cgi import FieldStorage
MULTIPART_ENVIRON = {'REQUEST_METHOD': 'POST'}
def parse_multipart(fp, ctype, clength, encoding):
[docs] """ Parse multipart/form-data request. Returns
a tuple (form, files).
"""
fs = FieldStorage(
fp=fp,
environ=MULTIPART_ENVIRON,
headers={
'content-type': ctype,
'content-length': clength
},
keep_blank_values=True
)
form = {}
files = {}
for f in fs.list:
if f.filename:
files.setdefault(f.name, []).append(f)
else:
form.setdefault(f.name, []).append(f.value)
return form, files
def parse_cookie(cookie):
[docs] """ Parse cookie string and return a dictionary
where key is a name of the cookie and value
is cookie value.
"""
return cookie and dict([pair.split('=', 1)
for pair in cookie.split('; ')]) or {}