Home | History | Annotate | Download | only in Lib

Lines Matching refs:url

1 """Open an arbitrary URL.
12 - RFC1808: the "relative URL" spec. (authoritative status)
13 - RFC1738 - the "URL standard". (authoritative status)
54 """OS-specific conversion from a relative URL of the 'file' scheme
59 """OS-specific conversion from a file system path to a relative URL
72 def urlopen(url, data=None, proxies=None, context=None):
73 """Create a file-like object for the specified URL to read from."""
87 return opener.open(url)
89 return opener.open(url, data)
90 def urlretrieve(url, filename=None, reporthook=None, data=None, context=None):
98 return opener.retrieve(url, filename, reporthook, data)
154 # in case you want logically independent URL openers
186 # percent encode url, fixing lame server errors for e.g, like space
187 # within url paths.
193 urltype, url = splittype(fullurl)
200 url = (host, fullurl) # Signal special case to open_*()
213 return getattr(self, name)(url)
215 return getattr(self, name)(url, data)
220 """Overridable interface to open unknown URL type."""
221 type, url = splittype(fullurl)
222 raise IOError, ('url error', 'unknown url type', type)
225 """Overridable interface to open unknown URL type."""
226 type, url = splittype(fullurl)
227 raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
230 def retrieve(self, url, filename=None, reporthook=None, data=None):
231 """retrieve(url) returns (filename, headers) for a local object
233 url = unwrap(toBytes(url))
234 if self.tempcache and url in self.tempcache:
235 return self.tempcache[url]
236 type, url1 = splittype(url)
245 fp = self.open(url, data)
252 garbage, path = splittype(url)
263 self.tempcache[url] = result
293 # Each method named open_<type> knows how to open that type of URL
295 def open_http(self, url, data=None):
300 if isinstance(url, str):
301 host, selector = splithost(url)
307 host, selector = url
310 # now we proceed with the url we want to obtain
312 url = rest
361 return addinfourl(fp, headers, "http:" + url, errcode)
364 return self.http_error(url, fp, errcode, errmsg, headers)
366 return self.http_error(url, fp, errcode, errmsg, headers, data)
368 def http_error(self, url, fp, errcode, errmsg, headers, data=None):
377 result = method(url, fp, errcode, errmsg, headers)
379 result = method(url, fp, errcode, errmsg, headers, data)
381 return self.http_error_default(url, fp, errcode, errmsg, headers)
383 def http_error_default(self, url, fp, errcode, errmsg, headers):
389 def open_https(self, url, data=None):
395 if isinstance(url, str):
396 host, selector = splithost(url)
402 host, selector = url
406 url = rest
454 return addinfourl(fp, headers, "https:" + url, errcode)
457 return self.http_error(url, fp, errcode, errmsg, headers)
459 return self.http_error(url, fp, errcode, errmsg, headers,
462 def open_file(self, url):
463 """Use local file or FTP depending on form of URL."""
464 if not isinstance(url, str):
466 if url[:2] == '//' and url[2:3] != '/' and url[2:12].lower() != 'localhost/':
467 return self.open_ftp(url)
469 return self.open_local_file(url)
471 def open_local_file(self, url):
478 host, file = splithost(url)
486 mtype = mimetypes.guess_type(url)[0]
495 raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url)
508 def open_ftp(self, url):
510 if not isinstance(url, str):
517 host, path = splithost(url)
559 mtype = mimetypes.guess_type("ftp:" + url)[0]
566 return addinfourl(fp, headers, "ftp:" + url)
570 def open_data(self, url, data=None):
571 """Use "data" URL."""
572 if not isinstance(url, str):
587 [type, data] = url.split(',', 1)
589 raise IOError, ('data error', 'bad data URL')
613 return addinfourl(f, headers, url)
625 def http_error_default(self, url, fp, errcode, errmsg, headers):
627 return addinfourl(fp, headers, "http:" + url, errcode)
629 def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
638 return meth(url, fp, 500,
641 result = self.redirect_internal(url, fp, errcode, errmsg,
647 def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
655 # In case the server sent a relative URL, join with original:
656 newurl = basejoin(self.type + ":" + url, newurl)
665 errmsg + " - Redirection to url '%s' is not allowed" %
671 def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
673 return self.http_error_302(url, fp, errcode, errmsg, headers, data)
675 def http_error_303(self, url, fp, errcode, errmsg, headers, data=None):
677 return self.http_error_302(url, fp, errcode, errmsg, headers, data)
679 def http_error_307(self, url, fp, errcode, errmsg, headers, data=None):
682 return self.http_error_302(url, fp, errcode, errmsg, headers, data)
684 return self.http_error_default(url, fp, errcode, errmsg, headers)
686 def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
690 URLopener.http_error_default(self, url, fp,
696 URLopener.http_error_default(self, url, fp,
700 URLopener.http_error_default(self, url, fp,
704 return getattr(self,name)(url, realm)
706 return getattr(self,name)(url, realm, data)
708 def http_error_407(self, url, fp, errcode, errmsg, headers, data=None):
712 URLopener.http_error_default(self, url, fp,
718 URLopener.http_error_default(self, url, fp,
722 URLopener.http_error_default(self, url, fp,
726 return getattr(self,name)(url, realm)
728 return getattr(self,name)(url, realm, data)
730 def retry_proxy_http_basic_auth(self, url, realm, data=None):
731 host, selector = splithost(url)
747 def retry_proxy_https_basic_auth(self, url, realm, data=None):
748 host, selector = splithost(url)
764 def retry_http_basic_auth(self, url, realm, data=None):
765 host, selector = splithost(url)
777 def retry_https_basic_auth(self, url, realm, data=None):
778 host, selector = splithost(url)
1017 def __init__(self, fp, headers, url, code=None):
1020 self.url = url
1030 return self.url
1034 # unwrap('<URL:type://host/path>') --> 'type://host/path'
1057 def toBytes(url):
1058 """toBytes(u"URL") --> 'URL'."""
1059 # Most URL schemes require ASCII. If that changes, the conversion
1061 if _is_unicode(url):
1063 url = url.encode("ASCII")
1065 raise UnicodeError("URL " + repr(url) +
1067 return url
1069 def unwrap(url):
1070 """unwrap('<URL:type://host/path>') --> 'type://host/path'."""
1071 url = url.strip()
1072 if url[:1] == '<' and url[-1:] == '>':
1073 url = url[1:-1].strip()
1074 if url[:4] == 'URL:': url = url[4:].strip()
1075 return url
1078 def splittype(url):
1085 match = _typeprog.match(url)
1088 return scheme.lower(), url[len(scheme) + 1:]
1089 return None, url
1092 def splithost(url):
1098 match = _hostprog.match(url)
1105 return None, url
1170 def splitquery(url):
1177 match = _queryprog.match(url)
1179 return url, None
1182 def splittag(url):
1189 match = _tagprog.match(url)
1191 return url, None
1193 def splitattr(url):
1196 words = url.split(';')
1264 Each part of a URL, e.g. the path info, the query, etc., has a
1273 Each of these characters is reserved in some component of a URL,
1277 section of a URL. Thus, it will not encode '/'. This character
1301 """Quote the query fragment of a URL; replacing ' ' with '+'"""
1308 """Encode a sequence of two-element tuples or dictionary into a URL query string.
1372 """Return a dictionary of scheme -> proxy server URL mappings.
1502 """Return a dictionary of scheme -> proxy server URL mappings.
1526 """Return a dictionary of scheme -> proxy server URL mappings.
1572 """Return a dictionary of scheme -> proxy server URL mappings.