Skip to content
Myr

Merge branch 'refactor-urls' of https://github.com/jerem/requests into develop

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 0b475dd, 2361a6f · Browse files · 2 files+25 added−27 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+25 added−27 removed

  • other:+25 added−27 removed

2 files+25 added−27 removed

modified:requests/models.py+1 added-16 removed
197 unmodified lines
198199 # Add the old request to the history collector.200 history.append(r)201202 # Redirect to...203 url = r.headers['location']202 url = cleanup_url(r.headers['location'], parent_url=self.url)203205 # Handle redirection without scheme (see: RFC 1808 Section 4)206 if url.startswith('//'):207 parsed_rurl = urlparse(r.url)208 url = '%s:%s' % (parsed_rurl.scheme, url)209210 # Facilitate non-RFC2616-compliant 'location' headers211 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')212 parsed_url = urlparse(url)213 if not parsed_url.netloc:214 parsed_url = list(parsed_url)215 parsed_url[2] = urllib.quote(parsed_url[2], safe="%/:=&?~#+!$,;'@()*[]")216 url = urljoin(r.url, str(urlunparse(parsed_url)))217204 # If 303, convert to idempotent GET.205 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4206 if r.status_code is codes.see_other:207 method = 'GET'
33 unmodified lines
241 # Give Response some context.242 self.response.request = self243244259245 def send(self, anyway=False):246 """Sends the shit."""247248 # Safety check.
242 unmodified lines
modified:requests/utils.py+24 added-11 removed
13 unmodified lines
14import cookielib15import re16import urllib17import zlib18from urlparse import urlparse, urlunparse18from urlparse import urlparse, urlunparse, urljoin192021def encode_params(params):22 """Encode parameters in a piece of data.
20 unmodified lines
4344 else:45 return params4647def cleanup_url(url, parent_url=None):48 # Handle redirection without scheme (see: RFC 1808 Section 4)49 if url.startswith('//'):50 parsed_rurl = urlparse(parent_url)51 url = '%s:%s' % (parsed_rurl.scheme, url)5248def build_url(url, query_params):49 """Build the actual URL to use."""5051 # Support for unicode domain names and paths.53 scheme, netloc, path, params, query, fragment = urlparse(url)54 if netloc:53 netloc = netloc.encode('idna')55 netloc = netloc.encode('idna')5657 if isinstance(path, unicode):56 path = path.encode('utf-8')58 path = path.encode('utf-8')5960 path = urllib.quote(path, safe="%/:=&?~#+!$,;'@()*[]")61 params = urllib.quote(params, safe="%/:=&?~#+!$,;'@()*[]")62 query = urllib.quote(query, safe="%/:=&?~#+!$,;'@()*[]")6360 url = str(urlunparse(61 [scheme, netloc, path, params, query, fragment]62 ))64 url = str(urlunparse([scheme, netloc, path, params, query, fragment]))6566 # Facilitate non-RFC2616-compliant 'location' headers67 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')68 if not netloc and parent_url:69 url = urljoin(parent_url, url)7071 return url7273def build_url(url, query_params):74 """Build the actual URL to use."""7576 url = cleanup_url(url)7778 query_params = encode_params(query_params)7980 if query_params:81 if urlparse(url).query:
2 unmodified lines
84 return '%s?%s' % (url, query_params)85 else:86 return url877488def header_expand(headers):89 """Returns an HTTP Header value string from a dictionary.9091 Example expansion::
304 unmodified lines