Parse multipart input. Arguments: fp : input file pdict: dictionary containing other parameters of content-type header encoding, errors: request encoding and error handler, passed to FieldStorage Returns a dictionary just like parse_qs(): keys are the field na
(fp, pdict, encoding="utf-8", errors="replace", separator='&')
| 197 | |
| 198 | |
| 199 | def parse_multipart(fp, pdict, encoding="utf-8", errors="replace", separator='&'): |
| 200 | """Parse multipart input. |
| 201 | |
| 202 | Arguments: |
| 203 | fp : input file |
| 204 | pdict: dictionary containing other parameters of content-type header |
| 205 | encoding, errors: request encoding and error handler, passed to |
| 206 | FieldStorage |
| 207 | |
| 208 | Returns a dictionary just like parse_qs(): keys are the field names, each |
| 209 | value is a list of values for that field. For non-file fields, the value |
| 210 | is a list of strings. |
| 211 | """ |
| 212 | # RFC 2046, Section 5.1 : The "multipart" boundary delimiters are always |
| 213 | # represented as 7bit US-ASCII. |
| 214 | boundary = pdict['boundary'].decode('ascii') |
| 215 | ctype = "multipart/form-data; boundary={}".format(boundary) |
| 216 | headers = Message() |
| 217 | headers.set_type(ctype) |
| 218 | try: |
| 219 | headers['Content-Length'] = pdict['CONTENT-LENGTH'] |
| 220 | except KeyError: |
| 221 | pass |
| 222 | fs = FieldStorage(fp, headers=headers, encoding=encoding, errors=errors, |
| 223 | environ={'REQUEST_METHOD': 'POST'}, separator=separator) |
| 224 | return {k: fs.getlist(k) for k in fs} |
| 225 | |
| 226 | def _parseparam(s): |
| 227 | while s[:1] == ';': |