Skip to content
Myr

Merge pull request #1640 from abarnert/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Accept per-file headers in multipart file POST messages.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 45873e2, af4fb8c · Browse files · 1 file+9 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−6 removed

  • other:+9 added−6 removed

1 file+9 added−6 removed

modified:requests/models.py+9 added-6 removed
15 unmodified lines
16from .structures import CaseInsensitiveDict1718from .auth import HTTPBasicAuth19from .cookies import cookiejar_from_dict, get_cookie_header20from .packages.urllib3.fields import RequestField21from .packages.urllib3.filepost import encode_multipart_formdata22from .packages.urllib3.util import parse_url23from .exceptions import (24 HTTPError, RequestException, MissingSchema, InvalidURL,
94 unmodified lines
119120 for (k, v) in files:121 # support for explicit filename122 ft = None123 fh = None124 if isinstance(v, (tuple, list)):125 if len(v) == 2:126 fn, fp = v125 else:127 elif len(v) == 3:128 fn, fp, ft = v129 else:130 fn, fp, ft, fh = v131 else:132 fn = guess_filename(v) or k133 fp = v134 if isinstance(fp, str):135 fp = StringIO(fp)136 if isinstance(fp, bytes):137 fp = BytesIO(fp)138135 if ft:136 new_v = (fn, fp.read(), ft)137 else:138 new_v = (fn, fp.read())139 new_fields.append((k, new_v))139 rf = RequestField(name=k, data=fp.read(), 140 filename=fn, headers=fh)141 rf.make_multipart(content_type=ft)142 new_fields.append(rf)143144 body, content_type = encode_multipart_formdata(new_fields)145146 return body, content_type
587 unmodified lines