models cleanup
authorKenneth Reitz <me@kennethreitz.com>
Sat, 12 Nov 2011 20:48:28 +0000 (12:48 -0800)
committerKenneth Reitz <me@kennethreitz.com>
Sat, 12 Nov 2011 20:48:28 +0000 (12:48 -0800)
requests/models.py

index 64641c56b9938773c7d065ec52e38c9fd0107f70..8bc2e3ad7d34082bb9151cb190703a97a2250d91 100644 (file)
@@ -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,