From: Mike Waldner Date: Wed, 24 Aug 2011 05:39:43 +0000 (-0400) Subject: Renaming vars. String formatting X-Git-Tag: v0.8.0~94^2~112^2~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfee8308772a3c931539688f9928ca6ff81d36cf;p=services%2Fpython-requests.git Renaming vars. String formatting #139 --- diff --git a/requests/utils.py b/requests/utils.py index 461582c..65ce4f7 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -168,40 +168,41 @@ def decode_gzip(content): return zlib.decompress(content, 16+zlib.MAX_WBITS) -def curl_from_request(request): - """Creates a curl command from the request.""" +def curl_from_request(request): + """Creates a curl command from the request.""" - #TODO - Files - #TODO - OAuth - #TODO - Cookies + #TODO - Files + #TODO - OAuth + #TODO - Cookies - #: -L/--location - if there is a redirect, redo request on the new place - curl = 'curl -L ' + #: -L/--location - if there is a redirect, redo request on the new place + curl = 'curl -L ' #: -u/--user - Specify the user name and password to use for server auth. - auth = '' - if request.auth is not None: + auth = '' + if request.auth is not None: auth = '-u "%s:%s" ' % (request.auth.username, request.auth.password) - if request.method.upper() == 'HEAD': - #: -I/--head - fetch headers only - method = '-I ' - else: - #: -X/--request - specify request method - method = '-X %s ' % request.method.upper() - - #: -H/--header - Extra header to use when getting a web page - header = '' - if request.headers: - header = header.join(['-H "%s:%s" ' % (k, v) for k, v in request.headers.iteritems()]) - - data = '' - if request.method in ('PUT', 'POST', 'PATCH'): - #: -d/--data - send specified data in post request. - if isinstance(request.data, (list, tuple)): - data = data.join(['-d "%s=%s" ' % (k, v) for (k, v) in request.data]) - elif request._enc_data is not None: - data = '-d %s ' % (request._enc_data) - - #: Params handled in _build_url - return curl + auth + method + header + data + '"' + request._build_url() + '"' + if request.method.upper() == 'HEAD': + #: -I/--head - fetch headers only + method = '-I ' + else: + #: -X/--request - specify request method + method = '-X %s ' % request.method.upper() + + #: -H/--header - Extra header to use when getting a web page + header = '' + if request.headers: + header = header.join(['-H "%s:%s" ' % (k, v) for k, v in request.headers.iteritems()]) + + data = '' + if request.method in ('PUT', 'POST', 'PATCH'): + #: -d/--data - send specified data in post request. + if isinstance(request.data, (list, tuple)): + data = data.join(['-d "%s=%s" ' % (k, v) for (k, v) in request.data]) + elif request._enc_data is not None: + data = '-d %s ' % (request._enc_data) + + + #: Params handled in _build_url + return curl + auth + method + header + data + '"' + request._build_url() + '"'