本文整理汇总了Python中urllib.url_quote函数的典型用法代码示例。如果您正苦于以下问题:Python url_quote函数的具体用法?Python url_quote怎么用?Python url_quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
def authenticate(self, environ):
""" This function takes a WSGI environment and authenticates
the request returning authenticated user or error.
"""
method = REQUEST_METHOD(environ)
fullpath = url_quote(SCRIPT_NAME(environ)) + url_quote(PATH_INFO(environ))
authorization = AUTHORIZATION(environ)
if not authorization:
return self.build_authentication()
(authmeth, auth) = authorization.split(" ", 1)
if "digest" != authmeth.lower():
return self.build_authentication()
amap = dict(_auth_to_kv_pairs(auth))
try:
username = amap["username"]
authpath = amap["uri"]
nonce = amap["nonce"]
realm = amap["realm"]
response = amap["response"]
assert authpath.split("?", 1)[0] in fullpath
assert realm == self.realm
qop = amap.get("qop", "")
cnonce = amap.get("cnonce", "")
nc = amap.get("nc", "00000000")
if qop:
assert "auth" == qop
assert nonce and nc
except:
return self.build_authentication()
ha1 = self.authfunc(environ, realm, username)
return self.compute(ha1, username, response, method, authpath, nonce, nc, cnonce, qop)
示例2: authenticate
def authenticate(self, environ):
""" This function takes a WSGI environment and authenticates
the request returning authenticated user or error.
"""
method = REQUEST_METHOD(environ)
fullpath = url_quote(SCRIPT_NAME(environ)) + url_quote(PATH_INFO(environ))
authorization = AUTHORIZATION(environ)
if not authorization:
return self.build_authentication()
(authmeth, auth) = authorization.split(" ", 1)
if 'digest' != authmeth.lower():
return self.build_authentication()
amap = {}
for itm in auth.split(", "):
(k,v) = [s.strip() for s in itm.split("=", 1)]
amap[k] = v.replace('"', '')
try:
username = amap['username']
authpath = amap['uri']
nonce = amap['nonce']
realm = amap['realm']
response = amap['response']
assert authpath.split("?", 1)[0] in fullpath
assert realm == self.realm
qop = amap.get('qop', '')
cnonce = amap.get('cnonce', '')
nc = amap.get('nc', '00000000')
if qop:
assert 'auth' == qop
assert nonce and nc
except:
return self.build_authentication()
ha1 = self.authfunc(environ, realm, username)
return self.compute(ha1, username, response, method, authpath,
nonce, nc, cnonce, qop)
示例3: proxy_exact_request
def proxy_exact_request(environ, start_response):
"""
HTTP proxying WSGI application that proxies the exact request
given in the environment. All controls are passed through the
environment.
This connects to the server given in SERVER_NAME:SERVER_PORT, and
sends the Host header in HTTP_HOST -- they do not have to match.
Does not add X-Forwarded-For or other standard headers
"""
scheme = environ['wsgi.url_scheme']
if scheme == 'http':
ConnClass = httplib.HTTPConnection
elif scheme == 'https':
ConnClass = httplib.HTTPSConnection
else:
raise ValueError(
"Unknown scheme: %r" % scheme)
conn = ConnClass('%(SERVER_NAME)s:%(SERVER_PORT)s' % environ)
headers = {}
for key, value in environ.items():
if key.startswith('HTTP_'):
key = key[5:].replace('_', '-').title()
headers[key] = value
path = (url_quote(environ.get('SCRIPT_NAME', ''))
+ url_quote(environ.get('PATH_INFO', '')))
if environ.get('QUERY_STRING'):
path += '?' + environ['QUERY_STRING']
try:
content_length = int(environ.get('CONTENT_LENGTH', '0'))
except ValueError:
content_length = 0
if content_length:
body = environ['wsgi.input'].read(content_length)
else:
body = ''
headers['Content-Length'] = content_length
if environ.get('CONTENT_TYPE'):
headers['Content-Type'] = environ['CONTENT_TYPE']
if not path.startswith("/"):
path = "/" + path
try:
conn.request(environ['REQUEST_METHOD'],
path, body, headers)
except socket.error, exc:
if exc.args[0] == -2:
# Name or service not known
exc = httpexceptions.HTTPBadGateway(
"Name or service not known (bad domain name: %s)"
% environ['SERVER_NAME'])
return exc(environ, start_response)
raise
示例4: __call__
def __call__(self, environ, start_response):
"""
HTTP proxying WSGI application that proxies the exact request
given in the environment. All controls are passed through the
environment.
This connects to the server given in SERVER_NAME:SERVER_PORT, and
sends the Host header in HTTP_HOST -- they do not have to match.
Does not add X-Forwarded-For or other standard headers
"""
if isinstance(self.address, basestring):
parsed_address = urlparse(self.address)
host = parsed_address.hostname
port = parsed_address.port
ConClass = self._get_conn_class(environ, parsed_address.scheme)
conn = ConnClass(parsed_address.hostname, parsed_address.port)
else:
conn = self._get_conn_class(environ)(*self.address)
headers = {}
for key, value in environ.items():
if key.startswith('HTTP_'):
key = key[5:].replace('_', '-').title()
headers[key] = value
path = (url_quote(environ.get('SCRIPT_NAME', ''))
+ url_quote(environ.get('PATH_INFO', '')))
if environ.get('QUERY_STRING'):
path += '?' + environ['QUERY_STRING']
try:
content_length = int(environ.get('CONTENT_LENGTH', '0'))
except ValueError:
content_length = 0
if content_length:
body = environ['wsgi.input'].read(content_length)
else:
body = ''
headers['Content-Length'] = content_length
if environ.get('CONTENT_TYPE'):
headers['Content-Type'] = environ['CONTENT_TYPE']
if not path.startswith("/"):
path = "/" + path
try:
conn.request(environ['REQUEST_METHOD'], path, body, headers)
except socket.error, exc:
if exc.args[0] == -2:
return http.BadGateway()(environ, start_response)
raise
示例5: _get_links
def _get_links(query):
"""Return all google result links."""
result = _get_result(SEARCH_URL.format(site=URL,
query=url_quote(query)))
html = pq(result)
return [a.attrib['href'] for a in html('.l')] or \
[a.attrib['href'] for a in html('.r')('a')]
示例6: api
def api(self, cmd, extras = '', no_session = False):
ret = {}
for _k1, api_url_k, _clienttype, _v in (('down', 'api_url', 'swjsq', 'do_down_accel'), ('up', 'api_up_url', 'uplink', 'do_up_accel')):
if not getattr(self, _v):
continue
while True:
# missing dial_account, (userid), os
api_url = getattr(self, api_url_k)
# TODO: phasing out time_and
url = 'http://%s/v2/%s?%sclient_type=android-%s-%s&peerid=%s&time_and=%d&client_version=android%s-%s&userid=%s&os=android-%s%s' % (
api_url,
cmd,
('sessionid=%s&' % self.xl_session) if not no_session else '',
_clienttype, APP_VERSION,
self.mac,
time.time() * 1000,
_clienttype, APP_VERSION,
self.xl_uid,
url_quote("%s.%s%s" % (OS_VERSION, OS_API_LEVEL, DEVICE_MODEL)),
('&%s' % extras) if extras else '',
)
try:
ret[_k1] = {}
ret[_k1] = json.loads(http_req(url, headers = header_api))
break
except URLError as ex:
uprint("Warning: error during %sapi connection: %s, use portal: %s" % (_k1, str(ex), api_url))
if (_k1 == 'down' and api_url == FALLBACK_PORTAL) or (_k1 == 'up' and api_url == FALLBACK_UPPORTAL):
print("Error: can't connect to %s api" % _k1)
os._exit(5)
if _k1 == 'down':
setattr(self, api_url_k, FALLBACK_PORTAL)
elif _k1 == 'up':
setattr(self, api_url_k, FALLBACK_UPPORTAL)
return ret
示例7: _add_playlist
def _add_playlist(self, **kwargs):
"""This method is private because the class method on :class:`Playlist`
should be used instead
:param kwargs: The values for the playlist. See \
`Add Playlist <http://developer.harvestmedia.net/working-with-members-2/add-a-member-playlist/>`_
"""
_client = kwargs.get('_client', None)
if not _client:
raise MissingParameter('You must pass _client to Playlist.add')
member_id = kwargs.get('member_id', None)
if not member_id:
raise MissingParameter('You must pass member_id to Playlist.add')
playlist_name = kwargs.get('playlist_name', None)
if not playlist_name:
raise MissingParameter('You must pass playlist_name to Playlist.add')
method_uri = '/addplaylist/{{service_token}}/%(member_id)s/%(playlist_name)s/' % \
{'member_id': member_id,
'playlist_name': url_quote(playlist_name.encode('utf-8'))}
xml_root = _client.get_xml(method_uri)
playlists = xml_root.find('playlists')
if playlists is not None:
for playlist_xml in playlists.getchildren():
name = playlist_xml.get('name')
if name == playlist_name:
return Playlist._from_xml(playlist_xml, _client)
示例8: add_slices
def add_slices(stats, aggregations, base):
slice_map = {}
for agg_key, agg in aggregations.items():
observations= []
slice_node = {
'dimension': agg_key.replace('.'+ID, ''),
'observation': observations
}
for bucket in agg['buckets']:
item_id = bucket.pop('key')
search_page_url = "{base}&{param}={value}".format(
base=base,
param=agg_key,
value=url_quote(item_id))
observation = {
'totalItems': bucket.pop('doc_count'),
'view': {ID: search_page_url},
'object': self.lookup(item_id)
}
observations.append(observation)
add_slices(observation, bucket, search_page_url)
if observations:
slice_map[agg_key] = slice_node
if slice_map:
stats['sliceByDimension'] = slice_map
示例9: index_html
def index_html(self, REQUEST=None, RESPONSE=None, charset='utf-8', disposition='inline'):
""" make it directly viewable when entering the objects URL """
if REQUEST is None:
REQUEST = self.REQUEST
if RESPONSE is None:
RESPONSE = REQUEST.RESPONSE
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
RESPONSE.setHeader('Content-Type', self.getContentType())
RESPONSE.setHeader('Accept-Ranges', 'bytes')
if handleIfModifiedSince(self, REQUEST, RESPONSE):
return ''
length = self.get_size()
RESPONSE.setHeader('Content-Length', length)
filename = self.getFilename()
if filename is not None:
if not isinstance(filename, unicode):
filename = unicode(filename, charset, errors="ignore")
quoted_filename = url_quote(filename.encode("utf8"))
filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
filename)
header_value = contentDispositionHeader(
disposition=disposition,
filename=filename)
# Add original filename in utf-8, ref to rfc2231
header_value = header_value + "; filename*=UTF-8''" + quoted_filename
RESPONSE.setHeader("Content-disposition", header_value)
request_range = handleRequestRange(self, length, REQUEST, RESPONSE)
return self.getIterator(**request_range)
示例10: __init__
def __init__(self, git_dir, hg_url):
self.hg_url = hg_url
self.hg_name = hg_name = url_quote(hg_url, safe="")
self.hg_repo_dir = os.path.join(git_dir, "hgremotes", hg_name)
if not os.path.exists(self.hg_repo_dir):
self.initialize_hg_repo()
self.git_repo_dir = os.path.join(self.hg_repo_dir, ".hg", "git")
示例11: setup
def setup(self):
"""Setup the instance."""
ldapi_socket = self.run_dir + "/ldapi"
self.ldapi_url = "ldapi://" + url_quote(ldapi_socket, "")
self.url_list = self.ldapi_url + " " + self.ldap_url
os.makedirs(self.conf_slapd_d_dir)
os.makedirs(self.run_dir)
os.makedirs(self.data_dir)
super(FakeAD, self)._setup_config()
self._setup_config()
# Start the daemon
super(FakeAD, self)._start_daemon()
# Relax requirement of surname attribute presence in person
modlist = [
(ldap.MOD_DELETE, "olcObjectClasses",
b"{4}( 2.5.6.6 NAME 'person' DESC 'RFC2256: a person' SUP top "
b"STRUCTURAL MUST ( sn $ cn ) MAY ( userPassword $ "
b"telephoneNumber $ seeAlso $ description ) )"),
(ldap.MOD_ADD, "olcObjectClasses",
b"{4}( 2.5.6.6 NAME 'person' DESC 'RFC2256: a person' SUP top "
b"STRUCTURAL MUST ( cn ) MAY ( sn $ userPassword $ "
b"telephoneNumber $ seeAlso $ description ) )"),
]
ldap_conn = ldap.initialize(self.ldapi_url)
ldap_conn.simple_bind_s(self.admin_rdn + ",cn=config", self.admin_pw)
ldap_conn.modify_s("cn={0}core,cn=schema,cn=config", modlist)
ldap_conn.unbind_s()
# restart daemon for reloading schema
super(FakeAD, self)._stop_daemon()
super(FakeAD, self)._start_daemon()
# Add data
ldap_conn = ldap.initialize(self.ldap_url)
ldap_conn.simple_bind_s(self.admin_dn, self.admin_pw)
ldap_conn.add_s(self.base_dn, [
("objectClass", [b"dcObject", b"organization"]),
("o", b"Example Company"),
])
ldap_conn.add_s("cn=Manager," + self.base_dn, [
("objectClass", b"organizationalRole"),
])
for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
ldap_conn.add_s("ou=" + ou + "," + self.base_dn, [
("objectClass", [b"top", b"organizationalUnit"]),
])
ldap_conn.unbind_s()
# import data from real AD
subprocess.check_call(
["ldapadd", "-x", "-w", self.admin_pw, "-D",
self.admin_dn, "-H", self.ldap_url,
"-f", "data/ad_data.ldif"],
)
示例12: clientside_actions
def clientside_actions(self, content_doc, log):
if self.content_href:
href = urlparse.urljoin(log.request.url, self.content_href)
url = '%s/.deliverance/subreq?url=%s&action=%s&content=%s&theme=%s' % (
log.request.application_url,
url_quote(href),
url_quote(self.name),
url_quote(str(self.content)),
url_quote(str(self.theme)))
return [{'mode': 'include',
'callback': url}]
if not self.if_content_matches(content_doc, log):
return []
content_type, content_els, content_attributes = self.select_elements(
self.content, content_doc, theme=False)
if not content_els:
if self.nocontent == 'abort':
## FIXME: uh oh
raise AbortTheme('No content matches content="%s"' % self.content)
else:
## FIXME: log
return []
theme_type, theme_selector = str(self.theme).split(':', 1)
data = {'type': self.name,
'mode': theme_type,
'selector': theme_selector}
if content_type == 'attributes' or content_type == 'tag':
data['attributes'] = dict(content_els[0].attrib)
if content_type == 'tag':
data['tag'] = content_els[0].tag
elif content_type == 'children':
text = []
for el in content_els:
text.append(el.text)
for child in el:
text.append(tostring(child))
data['content'] = ''.join(text)
elif content_type == 'elements':
text = []
for el in content_els:
## FIXME: sloppy :(
el.tail = None
text.append(tostring(el))
data['content'] = ''.join(text)
return [data]
示例13: posts
def posts(self, subscription_url, count=20):
"""
return posts of subscriptions
"""
url = "{subscription_url}{subscription}".format(
subscription_url=SUBSCRIPTION_URL,
subscription=url_quote(subscription_url, '')
)
return self.get_items(url, count)
示例14: transform
def transform(row, table):
file_data = tag_to_dict(row.filename)
absolute_url = url_join(URL_ROUTER_SEARCH,
url_quote(file_data['href']))
return {'date': extract_text(row.date),
'description': extract_text(row.description),
'filename': file_data['text'],
'size': extract_text(row.size),
'url': absolute_url, }
示例15: mkdtemp
def mkdtemp(self, prefix):
"""
Creates a new directory in the document root and returns its path and
URI.
"""
path = mkdtemp(prefix=prefix + "_", dir=self.docroot)
uri = joinURL("/", url_quote(os.path.basename(path))) + "/"
return (os.path.abspath(path), uri)