First commit of curl command from request

This commit is contained in:
Mike Waldner
2011-08-15 00:12:14 -04:00
parent 975720a30c
commit 430e87d0fd
+31
View File
@@ -328,6 +328,37 @@ class Request(object):
return self.sent
@property
def curl(self):
"""Creates a curl command from the request"""
#TODO - Auth. User names and accounts
#TODO - Query string...
#TODO - Files...How do I do files???
#: --location - if there is a redirect, redo request on the new place
curl_cmd = 'curl --location '
if self.method.upper() == 'HEAD':
#: --head - fetch headers only
method_opt = '--head '
else:
#: --request - specify request method
method_opt = '--request %s ' % self.method.upper()
data = ''
if self.method in ('PUT', 'POST', 'PATCH'):
#: --data - send specified data in post request.
#: '-data name=John -data skill=Doe' generates the
#: post chunk 'name=daniel&skill=lousy'
#if data is file:
if isinstance(self.data, (list, tuple)):
data = data.join(['--data ' + key + '=' + value + ' ' for key, value in self.data])
curl_cmd = curl_cmd + method_opt + data + self.url
return curl_cmd
class Response(object):