def test_quote_unreserved(self): '''Test a string of unreserved characters''' s = 'a~b_(c-d).' qs = urlquote(s) self.assertTrue('%' in qs) uqs = unquote_unreserved(qs) self.assertEqual(uqs, s) self.assertEqual(requote_uri(s), s) self.assertEqual(requote_uri(qs), s)
def test_quote_unreserved(self): """Test a string of unreserved characters""" s = "a~b_(c-d)." qs = urlquote(s) self.assertTrue("%" in qs) uqs = unquote_unreserved(qs) self.assertEqual(uqs, s) self.assertEqual(requote_uri(s), s) self.assertEqual(requote_uri(qs), s)
def _do_redirect(response, exc=None): request = response.request # done with current response url = response.headers.get('location') # Handle redirection without scheme (see: RFC 1808 Section 4) if url.startswith('//'): parsed_rurl = urlparse(request.full_url) url = '%s:%s' % (parsed_rurl.scheme, url) # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of # 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: url = urljoin( request.full_url, # Compliant with RFC3986, we percent # encode the url. requote_uri(url)) history = request.history if history and len(history) >= request.max_redirects: response.request_again = TooManyRedirects(response) else: params = request.inp_params.copy() params['history'] = copy(history) if history else [] params['history'].append(response) if response.status_code == 303: method = 'GET' params.pop('data', None) params.pop('files', None) else: method = request.method response.request_again = request_again(method, url, params)
def _do_redirect(self, response): request = response.request # done with current response url = response.headers.get('location') # Handle redirection without scheme (see: RFC 1808 Section 4) if url.startswith('//'): parsed_rurl = urlparse(request.full_url) url = '%s:%s' % (parsed_rurl.scheme, url) # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of # 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: url = urljoin(request.full_url, # Compliant with RFC3986, we percent # encode the url. requote_uri(url)) history = request.history if history and len(history) >= request.max_redirects: raise TooManyRedirects(response) params = request.inp_params.copy() params['history'] = copy(history) if history else [] params['history'].append(response) if response.status_code == 303: method = 'GET' params.pop('data', None) params.pop('files', None) else: method = request.method response.request_again = request_again(method, url, params) return response
def _do_redirect(response, exc=None): request = response.request # done with current response url = response.headers.get("location") # Handle redirection without scheme (see: RFC 1808 Section 4) if url.startswith("//"): parsed_rurl = urlparse(request.full_url) url = "%s:%s" % (parsed_rurl.scheme, url) # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of # 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: url = urljoin( request.full_url, # Compliant with RFC3986, we percent # encode the url. requote_uri(url), ) history = request.history if history and len(history) >= request.max_redirects: response.request_again = TooManyRedirects(response) else: params = request.inp_params.copy() params["history"] = copy(history) if history else [] params["history"].append(response) if response.status_code == 303: method = "GET" params.pop("data", None) params.pop("files", None) else: method = request.method response.request_again = request_again(method, url, params)
def full_url(url, params, method=None): p = urlparse(url) if not p.netloc and method == 'CONNECT': p = urlparse('http://%s' % url) params = mapping_iterator(params) query = parse_qsl(p.query, True) query.extend(split_url_params(params)) query = urlencode(query) return requote_uri( urlunparse((p.scheme, p.netloc, p.path, p.params, query, p.fragment)))
def full_url(url, params, method=None): p = urlparse(url) if not p.netloc and method == 'CONNECT': p = urlparse('http://%s' % url) params = mapping_iterator(params) query = parse_qsl(p.query, True) query.extend(split_url_params(params)) query = urlencode(query) return requote_uri( urlunparse((p.scheme, p.netloc, p.path, p.params, query, p.fragment)) )
def _quote_unreserved(self, s, qs): '''Test a string of unreserved characters''' uqs = unquote_unreserved(qs) self.assertEqual(uqs, s) self.assertEqual(requote_uri(s), s) self.assertEqual(requote_uri(qs), s)