当前位置: 首页>>代码示例>>Python>>正文


Python urlparse.urlsplit方法代码示例

本文整理汇总了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) 
开发者ID:sockeye44,项目名称:instavpn,代码行数:18,代码来源:pastee.py

示例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) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:18,代码来源:option.py

示例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 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:bulkloader.py

示例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) 
开发者ID:linuxscout,项目名称:mishkal,代码行数:25,代码来源:fixture.py

示例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 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:27,代码来源:base.py

示例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 
开发者ID:glmcdona,项目名称:meddle,代码行数:24,代码来源:urllib2.py

示例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') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_urlparse.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_urlparse.py

示例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 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:20,代码来源:yum.py

示例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,存在则打印出来 
开发者ID:sunshinelyz,项目名称:python-hacker,代码行数:18,代码来源:meta_image.py

示例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 
开发者ID:italia,项目名称:daf-recipes,代码行数:23,代码来源:model_dictize.py

示例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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:__init__.py

示例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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:15,代码来源:iri2uri.py

示例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 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:34,代码来源:utils.py

示例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 
开发者ID:jmarth,项目名称:plugin.video.kmediatorrent,代码行数:12,代码来源:rss.py


注:本文中的urlparse.urlsplit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。