mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
added mutlipart file=strings
This commit is contained in:
committed by
Shivaram Lingamneni
parent
7b6338c4b6
commit
ed7b14899f
+3
-1
@@ -32,7 +32,7 @@ from .utils import (
|
||||
DEFAULT_CA_BUNDLE_PATH)
|
||||
from .compat import (
|
||||
cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,
|
||||
is_py2)
|
||||
StringIO, is_py2)
|
||||
|
||||
# Import chardet if it is available.
|
||||
try:
|
||||
@@ -348,6 +348,8 @@ class Request(object):
|
||||
else:
|
||||
fn = guess_filename(v) or k
|
||||
fp = v
|
||||
if isinstance(fp, bytes):
|
||||
fp = StringIO(fp)
|
||||
fields.update({k: (fn, fp.read())})
|
||||
|
||||
(body, content_type) = encode_multipart_formdata(fields)
|
||||
|
||||
@@ -329,6 +329,21 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
|
||||
|
||||
self.assertEqual(post2.status_code, 200)
|
||||
|
||||
def test_POSTBIN_GET_POST_FILES_STRINGS(self):
|
||||
|
||||
for service in SERVICES:
|
||||
|
||||
url = service('post')
|
||||
|
||||
post1 = post(url, files={'fname.txt': 'fdata'})
|
||||
self.assertEqual(post1.status_code, 200)
|
||||
|
||||
post2 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':'more fdata'})
|
||||
self.assertEqual(post2.status_code, 200)
|
||||
|
||||
post3 = post(url, files={'fname.txt': 'fdata', 'fname2.txt':open(__file__,'rb')})
|
||||
self.assertEqual(post3.status_code, 200)
|
||||
|
||||
def test_nonzero_evaluation(self):
|
||||
|
||||
for service in SERVICES:
|
||||
|
||||
Reference in New Issue
Block a user