All Samples(1957) | Call(1402) | Derive(0) | Import(555)
Parse a URL into 5 components: <scheme>://<netloc>/<path>?<query>#<fragment> Return a 5-tuple: (scheme, netloc, path, query, fragment). Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.
def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components:
:///?#
Return a 5-tuple: (scheme, netloc, path, query, fragment).
Note that we don't break the components up in smaller bits
(e.g. netloc is a single string) and we don't expand % escapes."""
allow_fragments = bool(allow_fragments)
key = url, scheme, allow_fragments, type(url), type(scheme)
cached = _parse_cache.get(key, None)
if cached:
return cached
if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
clear_cache()
netloc = query = fragment = ''
i = url.find(':')
if i > 0:
if url[:i] == 'http': # optimize the common case
scheme = url[:i].lower()
url = url[i+1:]
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
if (('[' in netloc and ']' not in netloc) or
(']' in netloc and '[' not in netloc)):
raise ValueError("Invalid IPv6 URL")
if allow_fragments and '#' in url:
url, fragment = url.split('#', 1)
if '?' in url:
url, query = url.split('?', 1)
v = SplitResult(scheme, netloc, url, query, fragment)
_parse_cache[key] = v
return v
for c in url[:i]:
if c not in scheme_chars:
break
else:
scheme, url = url[:i].lower(), url[i+1:]
if url[:2] == '//':
netloc, url = _splitnetloc(url, 2)
if (('[' in netloc and ']' not in netloc) or
(']' in netloc and '[' not in netloc)):
raise ValueError("Invalid IPv6 URL")
if allow_fragments and scheme in uses_fragment and '#' in url:
url, fragment = url.split('#', 1)
if scheme in uses_query and '?' in url:
url, query = url.split('?', 1)
v = SplitResult(scheme, netloc, url, query, fragment)
_parse_cache[key] = v
return v
__date__ = '$Date: 2010-02-21 23:49:22 $'.split()[1].replace('/', '-')
__version__ = '$Revision: 1.48 $'
from urlparse import urlsplit, urljoin
from htmlentitydefs import name2codepoint
import sys, re
will be a Unicode string, decoded using the given charset. Giving the
'charset' argument overrides any received 'charset' parameter; a charset
of RAW ensures that the content is left undecoded in an 8-bit string."""
scheme, host, path, query, fragment = urlsplit(url)
host = host.split('@')[-1]
path = path or '/'
def setcookie(self, cookieline):
"""Put a cookie in this session's cookie jar. 'cookieline' should
have the format "<name>=<value>; domain=<domain>; path=<path>"."""
scheme, host, path, query, fragment = urlsplit(self.url)
host = host.split('@')[-1].split(':')[0]
setcookies(self.cookiejar, host, [cookieline])
src/t/w/twitstream-HEAD/examples/warehouse.py twitstream(Download)
#!/usr/bin/env python import sys import twitstream from urlparse import urlunsplit, urlsplit from binascii import unhexlify, hexlify
def urlparse(self, url):
(scheme, foo, rem, bar, baz) = urlsplit(url)
rem = rem.lstrip('/')
(locport, foo, path) = rem.partition('/')
(location, foo, port) = locport.partition(':')
if not port: port = 0
return (scheme, location, int(port), path)
src/p/y/Python_WebDAV_Library-0.2.0/src/webdav/WebdavClient.py Python_WebDAV_Library(Download)
from davlib import XML_CONTENT_TYPE from urlparse import urlsplit import re import types
"""
assert connection == None or isinstance(connection, Connection)
parts = urlsplit(url, allow_fragments=False)
self.path = parts[2]
self.validateResourceNames = validateResourceNames
@raise ValueError: If the URL does not contain valid/usable content.
"""
parts = urlsplit(url, allow_fragments=False)
if len(parts[0]) == 0 or len(parts[1]) == 0 or len(parts[2]) == 0:
raise ValueError("Invalid URL: " + repr(url))
src/c/o/CouchDB-0.8/couchdb/http.py CouchDB(Download)
except ImportError:
from dummy_threading import Lock
import urllib
from urlparse import urlsplit, urlunsplit
from couchdb import json
if authorization:
headers['Authorization'] = authorization
path_query = urlunsplit(('', '') + urlsplit(url)[2:4] + ('',))
conn = self._get_connection(url)
def _try_request_with_retries(retries):
def _get_connection(self, url):
scheme, host = urlsplit(url, 'http', False)[:2]
self.lock.acquire()
try:
conns = self.conns.setdefault((scheme, host), [])
if conns:
conn = conns.pop(-1)
def _return_connection(self, url, conn):
scheme, host = urlsplit(url, 'http', False)[:2]
self.lock.acquire()
try:
self.conns.setdefault((scheme, host), []).append(conn)
finally:
self.lock.release()
>>> extract_credentials('http://joe%40example.com:secret@localhost:5984/_config/')
('http://localhost:5984/_config/', ('joe@example.com', 'secret'))
"""
parts = urlsplit(url)
netloc = parts[1]
if '@' in netloc:
creds, netloc = netloc.split('@')
src/e/x/Exscript-v2.0/src/Exscript/util/url.py Exscript(Download)
Working with URLs (as used in URL formatted hostnames). """ import re, urllib from urlparse import urlparse, urlsplit _hextochr = dict() for i in range(256):
query = ''
if '?' in uri:
location, query = uri.split('?', 1)
components = urlsplit(location, 'http', 0)
netloc = components[1]
path = components[2]
auth = ''
src/e/x/exscript-HEAD/src/Exscript/util/url.py exscript(Download)
""" import re from urllib import urlencode, quote from urlparse import urlparse, urlsplit _hextochr = dict() for i in range(256):
url = 'http://' + url
# Parse the remaining url.
parsed = urlsplit(url, 'http', False)
netloc = parsed[1]
# Parse username and password.
src/p/s/pso-HEAD/trunk/py/pso/url.py pso(Download)
# __version__="$Revision: 122 $" from urlparse import urlsplit, urlunsplit from cgi import parse_qs from urllib import urlencode from xml.sax.saxutils import quoteattr from copy import deepcopy class Url(object): _query=None _script=None def __init__(self, url, scheme="html"): self.scheme, self.netlocation, self.path, query, self.fragment = urlsplit(url, scheme)
src/p/s/pso-HEAD/py/pso/url.py pso(Download)
# __version__="$Revision: 122 $" from urlparse import urlsplit, urlunsplit from cgi import parse_qs from urllib import urlencode from xml.sax.saxutils import quoteattr from copy import deepcopy class Url(object): _query=None _script=None def __init__(self, url, scheme="html"): self.scheme, self.netlocation, self.path, query, self.fragment = urlsplit(url, scheme)
src/s/u/SuperMario-HEAD/bububa/SuperMario/utils.py SuperMario(Download)
from datetime import datetime import threading import Queue from urlparse import urlsplit, urljoin, urlparse, urlunparse from eventlet.green.urllib import unquote, quote from eventlet.api import with_timeout from eventlet.db_pool import ConnectTimeout
def baseurl(url):
(proto, hostport, _x, _y, _z) = urlsplit(url)
return URL.normalize('%s://%s'%(proto, hostport))
@staticmethod
def link_title(data, url):
def bcheck(a, key):
src/e/n/enpraxis.educommons-3.2.1-final/enpraxis/educommons/extras/html2captioned.py enpraxis.educommons(Download)
from Products.CMFCore.utils import getToolByName import re from cgi import escape from urlparse import urlsplit, urljoin, urlunsplit from urllib import unquote_plus, quote_plus from Acquisition import aq_base from htmlentitydefs import name2codepoint
if not absurl.startswith(self.portal_base_url):
return 'external', None, url, ''
scheme, netloc, path, query, fragment = urlsplit(absurl)
path = path.strip('/')
tail = urlunsplit(('','','',query,fragment))
absurl = urlunsplit((scheme,netloc,path,'',''))
def makeUrlRelative(url, base):
"""Make a link relative to base.
This method assumes we have already checked that url and base have a common prefix.
"""
sheme, netloc, path, query, fragment = urlsplit(url)
_, _, basepath, _, _ = urlsplit(base)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next