Lines Matching refs:URL
8 RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter
14 RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zwinski, July 1998.
19 RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M.
136 def urlparse(url, scheme='', allow_fragments=True):
137 """Parse a URL into 6 components:
142 tuple = urlsplit(url, scheme, allow_fragments)
143 scheme, netloc, url, query, fragment = tuple
144 if scheme in uses_params and ';' in url:
145 url, params = _splitparams(url)
148 return ParseResult(scheme, netloc, url, params, query, fragment)
150 def _splitparams(url):
151 if '/' in url:
152 i = url.find(';', url.rfind('/'))
154 return url, ''
156 i = url.find(';')
157 return url[:i], url[i+1:]
159 def _splitnetloc(url, start=0):
160 delim = len(url) # position of end of domain part of url, default is end
162 wdelim = url.find(c, start) # find first of this delim
165 return url[start:delim], url[delim:] # return (domain, rest)
167 def urlsplit(url, scheme='', allow_fragments=True):
168 """Parse a URL into 5 components:
174 key = url, scheme, allow_fragments, type(url), type(scheme)
181 i = url.find(':')
183 if url[:i] == 'http': # optimize the common case
184 scheme = url[:i].lower()
185 url = url[i+1:]
186 if url[:2] == '//':
187 netloc, url = _splitnetloc(url, 2)
190 raise ValueError("Invalid IPv6 URL")
191 if allow_fragments and '#' in url:
192 url, fragment = url.split('#', 1)
193 if '?' in url:
194 url, query = url.split('?', 1)
195 v = SplitResult(scheme, netloc, url, query, fragment)
198 for c in url[:i]:
202 # make sure "url" is not actually a port number (in which case
204 rest = url[i+1:]
207 scheme, url = url[:i].lower(), rest
209 if url[:2] == '//':
210 netloc, url = _splitnetloc(url, 2)
213 raise ValueError("Invalid IPv6 URL")
214 if allow_fragments and '#' in url:
215 url, fragment = url.split('#', 1)
216 if '?' in url:
217 url, query = url.split('?', 1)
218 v = SplitResult(scheme, netloc, url, query, fragment)
223 """Put a parsed URL back together again. This may result in a
224 slightly different, but equivalent URL, if the URL that was parsed
227 scheme, netloc, url, params, query, fragment = data
229 url = "%s;%s" % (url, params)
230 return urlunsplit((scheme, netloc, url, query, fragment))
234 complete URL as a string. The data argument can be any five-item iterable.
235 This may result in a slightly different, but equivalent URL, if the URL that
238 scheme, netloc, url, query, fragment = data
239 if netloc or (scheme and scheme in uses_netloc and url[:2] != '//'):
240 if url and url[:1] != '/': url = '/' + url
241 url = '//' + (netloc or '') + url
243 url = scheme + ':' + url
245 url = url + '?' + query
247 url = url + '#' + fragment
248 return url
250 def urljoin(base, url, allow_fragments=True):
251 """Join a base URL and a possibly relative URL to form an absolute
254 return url
255 if not url:
260 urlparse(url, bscheme, allow_fragments)
262 return url
302 def urldefrag(url):
303 """Removes any existing fragment from URL.
305 Returns a tuple of the defragmented URL and the fragment. If
306 the URL contained no fragments, the second element is the
309 if '#' in url:
310 s, n, p, a, q, frag = urlparse(url)
314 return url, ''