本文整理汇总了Python中urlparse.quote方法的典型用法代码示例。如果您正苦于以下问题:Python urlparse.quote方法的具体用法?Python urlparse.quote怎么用?Python urlparse.quote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urlparse
的用法示例。
在下文中一共展示了urlparse.quote方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import quote [as 别名]
def __init__(self, options):
self._parse_options(options)
self._configure_session()
# urllib has different interface for py27 and py34
try:
self._urlencode = urllib.urlencode
self._quote = urllib.quote
self._urljoin = urlparse.urljoin
except AttributeError:
self._urlencode = urlparse.urlencode
self._quote = urlparse.quote
self._urljoin = urlparse.urljoin
示例2: url_quote
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import quote [as 别名]
def url_quote (self, text, plus = True):
if sys.version_info[0] < 3:
import urllib
if plus:
return urllib.quote_plus(text)
return urlparse.quote(text)
import urllib.parse
if plus:
return urllib.parse.quote_plus(text)
return urllib.parse.quote(text)
示例3: __init__
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import quote [as 别名]
def __init__(self, proxy_type, proxy_server_address):
pwd = ""
if State.username:
key = State.username
if State.domain != "":
key = State.domain + "\\" + State.username
pwd = keyring.get_password("Px", key)
if proxy_type == "NTLM":
if not pwd:
self.ctx = sspi.ClientAuth("NTLM",
os.environ.get("USERNAME"), scflags=0)
self.get_response = self.get_response_sspi
else:
self.ctx = ntlm_auth.ntlm.NtlmContext(
State.username, pwd, State.domain, "", ntlm_compatibility=3)
self.get_response = self.get_response_ntlm
elif proxy_type == "BASIC":
if not State.username:
dprint("No username configured for Basic authentication")
elif not pwd:
dprint("No password configured for Basic authentication")
else:
# Colons are forbidden in usernames and passwords for basic auth
# but since this can happen very easily, we make a special check
# just for colons so people immediately understand that and don't
# have to look up other resources.
if ":" in State.username or ":" in pwd:
dprint("Credentials contain invalid colon character")
else:
# Additionally check for invalid control characters as per
# RFC5234 Appendix B.1 (section CTL)
illegal_control_characters = "".join(
chr(i) for i in range(0x20)) + "\u007F"
if any(char in State.username or char in pwd
for char in illegal_control_characters):
dprint("Credentials contain invalid characters: %s" % ", ".join("0x" + "%x" % ord(char) for char in illegal_control_characters))
else:
# Remove newline appended by base64 function
self.ctx = b64encode(
"%s:%s" % (State.username, pwd))[:-1].decode()
self.get_response = self.get_response_basic
else:
principal = None
if pwd:
if State.domain:
principal = (urlparse.quote(State.username) + "@" +
urlparse.quote(State.domain) + ":" + urlparse.quote(pwd))
else:
principal = (urlparse.quote(State.username) + ":" +
urlparse.quote(pwd))
_, self.ctx = winkerberos.authGSSClientInit("HTTP@" +
proxy_server_address, principal=principal, gssflags=0,
mech_oid=winkerberos.GSS_MECH_OID_SPNEGO)
self.get_response = self.get_response_wkb
示例4: download
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import quote [as 别名]
def download(url, out=None, bar=bar_adaptive):
"""High level function, which downloads URL into tmp file in current
directory and then renames it to filename autodetected from either URL
or HTTP headers.
:param bar: function to track download progress (visualize etc.)
:param out: output filename or directory
:return: filename where URL is downloaded to
"""
# detect of out is a directory
outdir = None
if out and os.path.isdir(out):
outdir = out
out = None
# get filename for temp file in current directory
prefix = detect_filename(url, out)
(fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=prefix, dir=".")
os.close(fd)
os.unlink(tmpfile)
# set progress monitoring callback
def callback_charged(blocks, block_size, total_size):
# 'closure' to set bar drawing function in callback
callback_progress(blocks, block_size, total_size, bar_function=bar)
if bar:
callback = callback_charged
else:
callback = None
if PY3K:
# Python 3 can not quote URL as needed
binurl = list(urlparse.urlsplit(url))
binurl[2] = urlparse.quote(binurl[2])
binurl = urlparse.urlunsplit(binurl)
else:
binurl = url
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
filename = detect_filename(url, out, headers)
if outdir:
filename = outdir + "/" + filename
# add numeric ' (x)' suffix if filename already exists
if os.path.exists(filename):
filename = filename_fix_existing(filename)
shutil.move(tmpfile, filename)
#print headers
return filename
################################################################################
################################################################################
################################################################################
# T-LESS DOWNLOAD
示例5: download
# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import quote [as 别名]
def download(url, out=None, bar=bar_adaptive):
"""High level function, which downloads URL into tmp file in current
directory and then renames it to filename autodetected from either URL
or HTTP headers.
:param bar: function to track download progress (visualize etc.)
:param out: output filename or directory
:return: filename where URL is downloaded to
"""
# detect of out is a directory
outdir = None
if out and os.path.isdir(out):
outdir = out
out = None
# get filename for temp file in current directory
prefix = detect_filename(url, out)
(fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=prefix, dir=".")
os.close(fd)
os.unlink(tmpfile)
# set progress monitoring callback
def callback_charged(blocks, block_size, total_size):
# 'closure' to set bar drawing function in callback
callback_progress(blocks, block_size, total_size, bar_function=bar)
if bar:
callback = callback_charged
else:
callback = None
if PY3K:
# Python 3 can not quote URL as needed
binurl = list(urlparse.urlsplit(url))
binurl[2] = urlparse.quote(binurl[2])
binurl = urlparse.urlunsplit(binurl)
else:
binurl = url
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
filename = detect_filename(url, out, headers)
if outdir:
filename = outdir + "/" + filename
# add numeric ' (x)' suffix if filename already exists
if os.path.exists(filename):
filename = filename_fix_existing(filename)
shutil.move(tmpfile, filename)
#print headers
return filename