moving curl into utils
authorKenneth Reitz <me@kennethreitz.com>
Wed, 24 Aug 2011 03:52:43 +0000 (23:52 -0400)
committerKenneth Reitz <me@kennethreitz.com>
Wed, 24 Aug 2011 03:54:33 +0000 (23:54 -0400)
#139

requests/models.py
requests/utils.py

index 0d90ea92bfef7b886f55ed1d3c8e73c5685a11bc..5ff9eb48f3645b3eb86d977e9970fa25b1218e44 100644 (file)
@@ -383,41 +383,6 @@ class Request(object):
 
         return self.sent
 
-    @property
-    def curl(self):
-        """Creates a curl command from the request"""
-
-        #TODO - Auth with User names and accounts
-        #TODO - Files
-        #TODO - OAuth
-        #TODO - Cookies?
-
-        #: -L/--location - if there is a redirect, redo request on the new place
-        curl_cmd = 'curl -L '
-
-        #: -H/--header - Extra header to use when getting a web page
-        header = ''
-        if self.headers:
-            header = header.join(['-H "' + key + ':' + value + '" ' for key, value in self.headers.iteritems()])
-
-        if self.method.upper() == 'HEAD':
-            #: -I/--head - fetch headers only
-            method_opt = '-I '
-        else:
-            #: -X/--request - specify request method
-            method_opt = '-X %s ' % self.method.upper()
-
-        data = ''
-        if self.method in ('PUT', 'POST', 'PATCH'):
-            #: -d/--data - send specified data in post request.
-            if isinstance(self.data, (list, tuple)):
-                data = data.join(['-d ' + key + '=' + value + ' ' for key, value in self.data])
-            elif self._enc_data is not None:
-                data = '-d ' + self._enc_data + ' '
-
-        #: Params handled in _build_url
-        return curl_cmd + method_opt + data + header + '"' + self._build_url() + '"'
-
 
 class Response(object):
     """The core :class:`Response <Response>` object. All
index 2b55a164f438ff87d4568cfbff8a916a02bb7b2a..51ec4bfea8c5495f5fce8f91523feef686e6095d 100644 (file)
@@ -165,4 +165,39 @@ def decode_gzip(content):
     :param content: bytestring to gzip-decode.
     """
 
-    return zlib.decompress(content, 16+zlib.MAX_WBITS)
\ No newline at end of file
+    return zlib.decompress(content, 16+zlib.MAX_WBITS)
+
+
+def curl_from_request(request):
+    """Creates a curl command from the request."""
+
+    #TODO - Auth with User names and accounts
+    #TODO - Files
+    #TODO - OAuth
+    #TODO - Cookies?
+
+    #: -L/--location - if there is a redirect, redo request on the new place
+    curl_cmd = 'curl -L '
+
+    #: -H/--header - Extra header to use when getting a web page
+    header = ''
+    if request.headers:
+        header = header.join(['-H "' + key + ':' + value + '" ' for key, value in request.headers.iteritems()])
+
+    if request.method.upper() == 'HEAD':
+        #: -I/--head - fetch headers only
+        method_opt = '-I '
+    else:
+        #: -X/--request - specify request method
+        method_opt = '-X %s ' % request.method.upper()
+
+    data = ''
+    if request.method in ('PUT', 'POST', 'PATCH'):
+        #: -d/--data - send specified data in post request.
+        if isinstance(request.data, (list, tuple)):
+            data = data.join(['-d ' + key + '=' + value + ' ' for key, value in request.data])
+        elif request._enc_data is not None:
+            data = '-d ' + request._enc_data + ' '
+
+    #: Params handled in _build_url
+    return curl_cmd + method_opt + data + header + '"' + request._build_url() + '"'
\ No newline at end of file