Skip to content
Myr

Merge pull request #1537 from Lukasa/datetime

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

Allow non-string objects to be posted as data alongside files.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 4b6649e, f44b86e · Browse files · 2 files+12 added−0 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+12 added−0 removed

  • other:+12 added−0 removed

2 files+12 added−0 removed

modified:requests/models.py+4 added
104 unmodified lines
105 if isinstance(val, basestring) or not hasattr(val, '__iter__'):106 val = [val]107 for v in val:108 if v is not None:109 # Don't call str() on bytestrings: in Py3 it all goes wrong.110 if not isinstance(v, bytes):111 v = str(v)112113 new_fields.append(114 (field.decode('utf-8') if isinstance(field, bytes) else field,115 v.encode('utf-8') if isinstance(v, str) else v))116
615 unmodified lines
modified:test_requests.py+8 added
661 unmodified lines
662 # we go.663 self.assertTrue('unicode' in p.headers.keys())664 self.assertTrue('byte' in p.headers.keys())665666 def test_can_send_nonstring_objects_with_files(self):667 data = {'a': 0.0}668 files = {'b': 'foo'}669 r = requests.Request('POST', httpbin('post'), data=data, files=files)670 p = r.prepare()671672 self.assertTrue('multipart/form-data' in p.headers['Content-Type'])673674675class TestCaseInsensitiveDict(unittest.TestCase):676677 def test_mapping_init(self):678 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})
142 unmodified lines