Skip to content
Myr

Adding basic authentication. Also string formatting

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mike Waldner · committed by Mike Waldner · parent 2dfcc0b · Browse files · 1 file+16 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−12 removed

  • other:+16 added−12 removed

1 file+16 added−12 removed

modified:requests/utils.py+16 added-12 removed
169 unmodified lines
170171def curl_from_request(request):172 """Creates a curl command from the request."""173174 #TODO - Auth with User names and accounts174 #TODO - Files176 #TODO - OAuth177 #TODO - Cookies?175 #TODO - OAuth/Other Auths176 #TODO - Cookies177178 #: -L/--location - if there is a redirect, redo request on the new place180 curl_cmd = 'curl -L '179 curl = 'curl -L '180182 #: -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()])181 #: -u/--user - Specify the user name and password to use for server auth. 182 auth = ''183 if request.auth is not None:184 auth = '-u "%s:%s" ' % (request.auth.username, request.auth.password) 185186 if request.method.upper() == 'HEAD':187 #: -I/--head - fetch headers only189 method_opt = '-I '188 method = '-I '189 else:190 #: -X/--request - specify request method192 method_opt = '-X %s ' % request.method.upper()191 method = '-X %s ' % request.method.upper()192193 #: -H/--header - Extra header to use when getting a web page194 header = ''195 if request.headers:196 header = header.join(['-H "%s:%s" ' % (k, v) for k, v in request.headers.iteritems()])197198 data = ''199 if request.method in ('PUT', 'POST', 'PATCH'):200 #: -d/--data - send specified data in post request.201 if isinstance(request.data, (list, tuple)):198 data = data.join(['-d %s=%s ' % (k, v) for (k, v) in request.data])202 data = data.join(['-d "%s=%s" ' % (k, v) for (k, v) in request.data])203 elif request._enc_data is not None:204 data = '-d %s ' % (request._enc_data)205206 #: Params handled in _build_url203 return curl_cmd + method_opt + data + header + '"' + request._build_url() + '"'207 return curl + auth + method + header + data + '"' + request._build_url() + '"'