本文整理匯總了Python中urlparse.urlsplit方法的典型用法代碼示例。如果您正苦於以下問題:Python urlparse.urlsplit方法的具體用法?Python urlparse.urlsplit怎麽用?Python urlparse.urlsplit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urlparse
的用法示例。
在下文中一共展示了urlparse.urlsplit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _clean_url
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def _clean_url(url):
p = urlparse.urlsplit(url)
scheme = p[0]
netloc_split = p[1].split(":")
hostname = netloc_split[0]
if len(netloc_split) > 1:
port = int(netloc_split[1])
else:
port = scheme == "https" and 443 or 80
path = p[2]
port_str = ""
if port != 80 and scheme == "http":
port_str = ":%d" % port
elif port != 443 and scheme == "https":
port_str = ":%d" % port
return "%s://%s%s%s" % (scheme, hostname, port_str, path)
示例2: _setHTTPProxy
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def _setHTTPProxy():
"""
Check and set the HTTP/SOCKS proxy for all HTTP requests.
"""
if not conf.proxy:
return
infoMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)
try:
_ = urlparse.urlsplit(conf.proxy)
except Exception, ex:
errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, ex)
raise PocsuiteSyntaxException(errMsg)
示例3: _GetRemoteAppId
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def _GetRemoteAppId(url, throttle, email, passin,
raw_input_fn=raw_input, password_input_fn=getpass.getpass,
throttle_class=None):
"""Get the App ID from the remote server."""
scheme, host_port, url_path, _, _ = urlparse.urlsplit(url)
secure = (scheme == 'https')
throttled_rpc_server_factory = (
remote_api_throttle.ThrottledHttpRpcServerFactory(
throttle, throttle_class=throttle_class))
def AuthFunction():
return _AuthFunction(host_port, email, passin, raw_input_fn,
password_input_fn)
app_id, server = remote_api_stub.GetRemoteAppId(
host_port, url_path, AuthFunction,
rpc_server_factory=throttled_rpc_server_factory, secure=secure)
return app_id, server
示例4: goto
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def goto(self, href, method='get', **args):
"""
Go to the (potentially relative) link ``href``, using the
given method (``'get'`` or ``'post'``) and any extra arguments
you want to pass to the ``app.get()`` or ``app.post()``
methods.
All hostnames and schemes will be ignored.
"""
scheme, host, path, query, fragment = urlparse.urlsplit(href)
# We
scheme = host = fragment = ''
href = urlparse.urlunsplit((scheme, host, path, query, fragment))
href = urlparse.urljoin(self.request.full_url, href)
method = method.lower()
assert method in ('get', 'post'), (
'Only "get" or "post" are allowed for method (you gave %r)'
% method)
if method == 'get':
method = self.test_app.get
else:
method = self.test_app.post
return method(href, **args)
示例5: unshorten
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def unshorten(self, uri, type=None):
domain = urlsplit(uri).netloc
if not domain:
return uri, "No domain found in URI!"
had_google_outbound, uri = self._clear_google_outbound_proxy(uri)
if re.search(self._adfly_regex, domain, re.IGNORECASE) or type == 'adfly':
return self._unshorten_adfly(uri)
if re.search(self._adfocus_regex, domain, re.IGNORECASE) or type == 'adfocus':
return self._unshorten_adfocus(uri)
if re.search(self._linkbucks_regex, domain, re.IGNORECASE) or type == 'linkbucks':
return self._unshorten_linkbucks(uri)
if re.search(self._lnxlu_regex, domain, re.IGNORECASE) or type == 'lnxlu':
return self._unshorten_lnxlu(uri)
if re.search(self._shst_regex, domain, re.IGNORECASE):
return self._unshorten_shst(uri)
if re.search(self._hrefli_regex, domain, re.IGNORECASE):
return self._unshorten_hrefli(uri)
if re.search(self._anonymz_regex, domain, re.IGNORECASE):
return self._unshorten_anonymz(uri)
return uri, 200
示例6: reduce_uri
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def reduce_uri(self, uri, default_port=True):
"""Accept authority or URI and extract only the authority and path."""
# note HTTP URLs do not have a userinfo component
parts = urlparse.urlsplit(uri)
if parts[1]:
# URI
scheme = parts[0]
authority = parts[1]
path = parts[2] or '/'
else:
# host or host:port
scheme = None
authority = uri
path = '/'
host, port = splitport(authority)
if default_port and port is None and scheme is not None:
dport = {"http": 80,
"https": 443,
}.get(scheme)
if dport is not None:
authority = "%s:%d" % (host, dport)
return authority, path
示例7: test_issue14072
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def test_issue14072(self):
p1 = urlparse.urlsplit('tel:+31-641044153')
self.assertEqual(p1.scheme, 'tel')
self.assertEqual(p1.path, '+31-641044153')
p2 = urlparse.urlsplit('tel:+31641044153')
self.assertEqual(p2.scheme, 'tel')
self.assertEqual(p2.path, '+31641044153')
# Assert for urlparse
p1 = urlparse.urlparse('tel:+31-641044153')
self.assertEqual(p1.scheme, 'tel')
self.assertEqual(p1.path, '+31-641044153')
p2 = urlparse.urlparse('tel:+31641044153')
self.assertEqual(p2.scheme, 'tel')
self.assertEqual(p2.path, '+31641044153')
示例8: test_attributes_without_netloc
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def test_attributes_without_netloc(self):
# This example is straight from RFC 3261. It looks like it
# should allow the username, hostname, and port to be filled
# in, but doesn't. Since it's a URI and doesn't use the
# scheme://netloc syntax, the netloc and related attributes
# should be left empty.
uri = "sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15"
p = urlparse.urlsplit(uri)
self.assertEqual(p.netloc, "")
self.assertEqual(p.username, None)
self.assertEqual(p.password, None)
self.assertEqual(p.hostname, None)
self.assertEqual(p.port, None)
self.assertEqual(p.geturl(), uri)
p = urlparse.urlparse(uri)
self.assertEqual(p.netloc, "")
self.assertEqual(p.username, None)
self.assertEqual(p.password, None)
self.assertEqual(p.hostname, None)
self.assertEqual(p.port, None)
self.assertEqual(p.geturl(), uri)
示例9: filename
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def filename(self):
'''Returns the filename to be used for saving the repo file.
The filename is derived from the repo url by injecting a suffix
after the name and before the file extension. This suffix is a
partial md5 checksum of the full repourl. This avoids multiple
repos from being written to the same file.
'''
urlpath = unquote(urlsplit(self.repourl, allow_fragments=False).path)
basename = os.path.basename(urlpath)
if not basename.endswith(REPO_SUFFIX):
basename += REPO_SUFFIX
if self.add_hash:
suffix = '-' + md5(self.repourl.encode('utf-8')).hexdigest()[:5] # nosec
else:
suffix = ''
final_name = suffix.join(os.path.splitext(basename))
return final_name
示例10: downloadImage
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def downloadImage(imgTag):
try:
print '[+] Downloading image...'
imgSrc = imgTag['src']
#將圖片的二進製內容讀取到變量imgContent中
imgContent = urllib2.urlopen(imgSrc).read()
imgFileName = basename(urlsplit(imgSrc)[2])
imgFile = open(imgFileName, 'wb')
imgFile.write(imgContent)
imgFile.close()
return imgFileName
except:
return ''
#檢查是否存在GPS,存在則打印出來
示例11: resource_dictize
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def resource_dictize(res, context):
model = context['model']
resource = d.table_dictize(res, context)
extras = resource.pop("extras", None)
if extras:
resource.update(extras)
# some urls do not have the protocol this adds http:// to these
url = resource['url']
## for_edit is only called at the times when the dataset is to be edited
## in the frontend. Without for_edit the whole qualified url is returned.
if resource.get('url_type') == 'upload' and not context.get('for_edit'):
cleaned_name = munge.munge_filename(url)
resource['url'] = h.url_for(controller='package',
action='resource_download',
id=resource['package_id'],
resource_id=res.id,
filename=cleaned_name,
qualified=True)
elif resource['url'] and not urlparse.urlsplit(url).scheme and not context.get('for_edit'):
resource['url'] = u'http://' + url.lstrip('/')
return resource
示例12: urldefrag
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def urldefrag(url):
if "#" in url:
s, n, p, q, frag = urlsplit(url)
defrag = urlunsplit((s, n, p, q, ''))
else:
defrag = url
frag = ''
return defrag, frag
示例13: iri2uri
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def iri2uri(uri):
"""Convert an IRI to a URI. Note that IRIs must be
passed in a unicode strings. That is, do not utf-8 encode
the IRI before passing it into the function."""
if isinstance(uri, unicode):
(scheme, authority, path, query, fragment) = urlparse.urlsplit(uri)
authority = authority.encode("idna")
# For each character in 'ucschar' or 'iprivate'
# 1. encode as utf-8
# 2. then %-encode each octet of that utf-8
uri = urlparse.urlunsplit((scheme, authority, path, query, fragment))
uri = "".join([encode(c) for c in uri])
return uri
示例14: url_get
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def url_get(url, params={}, headers={}, with_immunicity=True):
import urllib2
from contextlib import closing
from kmediatorrent import plugin
from kmediatorrent.common import USER_AGENT
if params:
import urllib
url = "%s?%s" % (url, urllib.urlencode(params))
req = urllib2.Request(url)
req.add_header("User-Agent", USER_AGENT)
for k, v in headers.items():
req.add_header(k, v)
if with_immunicity and plugin.get_setting("immunicity", bool):
from kmediatorrent import immunicity
proxy = immunicity.get_proxy_for(url)
if proxy:
from urlparse import urlsplit
parts = urlsplit(url)
req.set_proxy(proxy, parts[0])
try:
with closing(urllib2.urlopen(req)) as response:
data = response.read()
if response.headers.get("Content-Encoding", "") == "gzip":
import zlib
return zlib.decompressobj(16 + zlib.MAX_WBITS).decompress(data)
return data
except urllib2.HTTPError:
return None
示例15: get_file_name
# 需要導入模塊: import urlparse [as 別名]
# 或者: from urlparse import urlsplit [as 別名]
def get_file_name(href):
import urlparse
if href.startswith("magnet:"):
magnet_args = urlparse.parse_qs(href.replace("magnet:?", "")) # I know about urlparse.urlsplit but this is faster
if magnet_args["dn"]:
return magnet_args["dn"][0]
else:
path = urlparse.urlsplit(href)[2]
filename = path.split("/")[-1]
return filename