Skip to content
Myr

Merge pull request #2468 from scholer/master

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

Support for bytearray when creating Request with files argument, just like str and bytes.

authored by Ian Cordasco · committed by Ian Cordasco · parents 461b740, 1887f32 · Browse files · 2 files+14 added−1 removed
This commit

State

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

Diff stats

2 files+14 added−1 removed

  • other:+14 added−1 removed

2 files+14 added−1 removed

modified:requests/models.py+1 added-1 removed
143 unmodified lines
144 fn = guess_filename(v) or k145 fp = v146 if isinstance(fp, str):147 fp = StringIO(fp)148 if isinstance(fp, bytes):148 if isinstance(fp, (bytes, bytearray)):149 fp = BytesIO(fp)150151 rf = RequestField(name=k, data=fp.read(),152 filename=fn, headers=fh)
687 unmodified lines
modified:test_requests.py+13 added
933 unmodified lines
934 p = r.prepare()935936 assert 'multipart/form-data' in p.headers['Content-Type']937938 def test_can_send_bytes_bytearray_objects_with_files(self):939 # Test bytes:940 data = {'a': 'this is a string'}941 files = {'b': b'foo'}942 r = requests.Request('POST', httpbin('post'), data=data, files=files)943 p = r.prepare()944 assert 'multipart/form-data' in p.headers['Content-Type']945 # Test bytearrays:946 files = {'b': bytearray(b'foo')}947 r = requests.Request('POST', httpbin('post'), data=data, files=files)948 p = r.prepare()949 assert 'multipart/form-data' in p.headers['Content-Type']950951 def test_can_send_file_object_with_non_string_filename(self):952 f = io.BytesIO()953 f.name = 2954 r = requests.Request('POST', httpbin('post'), files={'f': f})
661 unmodified lines