From: Kenneth Reitz Date: Sat, 12 Nov 2011 20:48:28 +0000 (-0800) Subject: models cleanup X-Git-Tag: v0.8.0~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0d8e8e8467a337f7ad0a10206b64087d8eef14a;p=services%2Fpython-requests.git models cleanup --- diff --git a/requests/models.py b/requests/models.py index 64641c5..8bc2e3a 100644 --- a/requests/models.py +++ b/requests/models.py @@ -23,6 +23,7 @@ from .packages.urllib3.exceptions import MaxRetryError from .packages.urllib3.exceptions import SSLError as _SSLError from .packages.urllib3.exceptions import HTTPError as _HTTPError from .packages.urllib3 import connectionpool, poolmanager +from .packages.urllib3.filepost import encode_multipart_formdata from .exceptions import ( Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError) from .utils import ( @@ -30,6 +31,8 @@ from .utils import ( stream_decode_response_unicode, decode_gzip, stream_decode_gzip) + + REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved) @@ -330,8 +333,6 @@ class Request(object): body = None content_type = None - from .packages.urllib3.filepost import encode_multipart_formdata - # Multi-part file uploads. if self.files: if not isinstance(self.data, basestring): @@ -349,8 +350,12 @@ class Request(object): # TODO: Conflict? else: if self.data: + body = self._enc_data - content_type = 'application/x-www-form-urlencoded' + if isinstance(self.data, basestring): + content_type = None + else: + content_type = 'application/x-www-form-urlencoded' # Add content-type if it wasn't explicitly provided. if (content_type) and (not 'content-type' in self.headers): @@ -398,6 +403,7 @@ class Request(object): try: # Send the request. + r = conn.urlopen( method=self.method, url=url,