mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
+3
-2
@@ -28,7 +28,7 @@ from .exceptions import (
|
||||
Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError)
|
||||
from .utils import (
|
||||
get_unicode_from_response, stream_decode_response_unicode,
|
||||
decode_gzip, stream_decode_gzip)
|
||||
decode_gzip, stream_decode_gzip, guess_filename)
|
||||
|
||||
|
||||
|
||||
@@ -346,7 +346,8 @@ class Request(object):
|
||||
fields = dict(self.data)
|
||||
|
||||
for (k, v) in self.files.items():
|
||||
fields.update({k: (k, v.read())})
|
||||
fields.update({k: (guess_filename(k) or k, v.read())})
|
||||
|
||||
(body, content_type) = encode_multipart_formdata(fields)
|
||||
else:
|
||||
pass
|
||||
|
||||
@@ -20,6 +20,12 @@ import zlib
|
||||
from urllib2 import parse_http_list as _parse_list_header
|
||||
|
||||
|
||||
def guess_filename(obj):
|
||||
"""Tries to guess the filename of the given object."""
|
||||
name = getattr(obj, 'name', None)
|
||||
if name and name[0] != '<' and name[-1] != '>':
|
||||
return name
|
||||
|
||||
# From mitsuhiko/werkzeug (used with permission).
|
||||
def parse_list_header(value):
|
||||
"""Parse lists as described by RFC 2068 Section 2.
|
||||
|
||||
Reference in New Issue
Block a user