Skip to content
Myr

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

2 files+36 added−36 removed

modified:requests/models.py-35 removed
381 unmodified lines
382 self.sent = self.response.ok383384 return self.sent385386 @property387 def curl(self):388 """Creates a curl command from the request"""386390 #TODO - Auth with User names and accounts391 #TODO - Files392 #TODO - OAuth393 #TODO - Cookies?394395 #: -L/--location - if there is a redirect, redo request on the new place396 curl_cmd = 'curl -L '397398 #: -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()])402403 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()409410 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 + ' '417418 #: Params handled in _build_url419 return curl_cmd + method_opt + data + header + '"' + self._build_url() + '"'420421387class Response(object):388 """The core :class:`Response <Response>` object. All389 :class:`Request <Request>` objects contain a390 :class:`response <Response>` attribute, which is an instance
256 unmodified lines
modified:requests/utils.py+36 added-1 removed
163 unmodified lines
164165 :param content: bytestring to gzip-decode.166 """167168 return zlib.decompress(content, 16+zlib.MAX_WBITS)168 return zlib.decompress(content, 16+zlib.MAX_WBITS)169170171def curl_from_request(request):172 """Creates a curl command from the request."""173174 #TODO - Auth with User names and accounts175 #TODO - Files176 #TODO - OAuth177 #TODO - Cookies?178179 #: -L/--location - if there is a redirect, redo request on the new place180 curl_cmd = 'curl -L '181182 #: -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()])186187 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()193194 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 + ' '201202 #: Params handled in _build_url203 return curl_cmd + method_opt + data + header + '"' + request._build_url() + '"'