From: Mike Waldner Date: Mon, 15 Aug 2011 04:12:14 +0000 (-0400) Subject: First commit of curl command from request X-Git-Tag: v0.8.0~94^2~112^2~12^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=430e87d0fd738adde494ccfe7d3fb3882fd8ca02;p=services%2Fpython-requests.git First commit of curl command from request --- diff --git a/requests/models.py b/requests/models.py index 08f3e32..9e0b0dd 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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):