Merge remote-tracking branch 'upstream/develop' into develop
authorMike Waldner <mwaldner@gilt.com>
Wed, 24 Aug 2011 02:22:51 +0000 (22:22 -0400)
committerMike Waldner <mwaldner@gilt.com>
Wed, 24 Aug 2011 02:22:51 +0000 (22:22 -0400)
1  2 
requests/models.py

index ec18b08ca21c35105d18a67a6a8b7d343e0d84c4,5983c237d2b0f6ee1a813774b0d09849e5106b55..7a9ba098bb5e3b0a4a3ba14a330ba8e015eaf634
@@@ -328,48 -384,11 +384,47 @@@ 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
 +
 +        #: -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.
 +            #: '-d name=John -d last=Doe' generates the
 +            #: post chunk 'name=John&last=Doe'
 +
 +            if isinstance(self.data, (list, tuple)):
 +                data = data.join(['-d ' + key + '=' + value + ' ' for key, value in self.data])
 +            else:
 +                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 <models.Response>` object. All
-     :class:`Request <models.Request>` objects contain a
-     :class:`response <models.Response>` attribute, which is an instance
+     """The core :class:`Response <Response>` object. All
+     :class:`Request <Request>` objects contain a
+     :class:`response <Response>` attribute, which is an instance
      of this class.
      """