moving curl into utils
Before adoption: this commit came in with the history the project adopted, so no landing records it.
#139
authored by Kenneth Reitz · committed by Kenneth Reitz · parent a276ebd · Browse files · 2 files·+36 added−36 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+36 added−36 removed
- other:+36 added−36 removed
Provenance
- Commit
256c86f- Tree
c73db86- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
a276ebd
2 files changed+36 added−36 removed
modified:requests/models.py-35 removed
381 unmodified lines382 self.sent = self.response.ok383 384 return self.sent385 386- @property387- def curl(self):388- """Creates a curl command from the request"""386 390- #TODO - Auth with User names and accounts391- #TODO - Files392- #TODO - OAuth393- #TODO - Cookies?394-395- #: -L/--location - if there is a redirect, redo request on the new place396- curl_cmd = 'curl -L '397-398- #: -H/--header - Extra header to use when getting a web page399- header = ''400- if self.headers:401- header = header.join(['-H "' + key + ':' + value + '" ' for key, value in self.headers.iteritems()])402-403- if self.method.upper() == 'HEAD':404- #: -I/--head - fetch headers only405- method_opt = '-I '406- else:407- #: -X/--request - specify request method408- method_opt = '-X %s ' % self.method.upper()409-410- data = ''411- if self.method in ('PUT', 'POST', 'PATCH'):412- #: -d/--data - send specified data in post request.413- if isinstance(self.data, (list, tuple)):414- data = data.join(['-d ' + key + '=' + value + ' ' for key, value in self.data])415- elif self._enc_data is not None:416- data = '-d ' + self._enc_data + ' '417-418- #: Params handled in _build_url419- return curl_cmd + method_opt + data + header + '"' + self._build_url() + '"'420-421-387 class Response(object):388 """The core :class:`Response <Response>` object. All389 :class:`Request <Request>` objects contain a390 :class:`response <Response>` attribute, which is an instance256 unmodified linesmodified:requests/utils.py+36 added-1 removed
163 unmodified lines164 165 :param content: bytestring to gzip-decode.166 """167 168- return zlib.decompress(content, 16+zlib.MAX_WBITS)168+ return zlib.decompress(content, 16+zlib.MAX_WBITS)169+170+171+def curl_from_request(request):172+ """Creates a curl command from the request."""173+174+ #TODO - Auth with User names and accounts175+ #TODO - Files176+ #TODO - OAuth177+ #TODO - Cookies?178+179+ #: -L/--location - if there is a redirect, redo request on the new place180+ curl_cmd = 'curl -L '181+182+ #: -H/--header - Extra header to use when getting a web page183+ header = ''184+ if request.headers:185+ header = header.join(['-H "' + key + ':' + value + '" ' for key, value in request.headers.iteritems()])186+187+ if request.method.upper() == 'HEAD':188+ #: -I/--head - fetch headers only189+ method_opt = '-I '190+ else:191+ #: -X/--request - specify request method192+ method_opt = '-X %s ' % request.method.upper()193+194+ data = ''195+ if request.method in ('PUT', 'POST', 'PATCH'):196+ #: -d/--data - send specified data in post request.197+ if isinstance(request.data, (list, tuple)):198+ data = data.join(['-d ' + key + '=' + value + ' ' for key, value in request.data])199+ elif request._enc_data is not None:200+ data = '-d ' + request._enc_data + ' '201+202+ #: Params handled in _build_url203+ return curl_cmd + method_opt + data + header + '"' + request._build_url() + '"'