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


Python urllib.splitnport方法代码示例

本文整理汇总了Python中urllib.splitnport方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.splitnport方法的具体用法?Python urllib.splitnport怎么用?Python urllib.splitnport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib的用法示例。


在下文中一共展示了urllib.splitnport方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_server

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def add_server(self, netloc, path, config):
        """Add a new CherryPy Application for a Virtual Host.
        Creates a new CherryPy WSGI Server instance if the host resolves
        to a different IP address or port.
        """

        from cherrypy._cpwsgi_server import CPWSGIServer
        from cherrypy.process.servers import ServerAdapter

        host, port = urllib.splitnport(netloc, 80)
        host = socket.gethostbyname(host)
        bind_addr = (host, port)
        if bind_addr not in self.servers:
            self.servers.append(bind_addr)
            server = CPWSGIServer()
            server.bind_addr = bind_addr
            adapter = ServerAdapter(cherrypy.engine, server, server.bind_addr)
            adapter.subscribe()
        self.domains[netloc] = cherrypy.Application(root=None,
            config={path.rstrip('/') or '/': config}) 
开发者ID:diegojromerolopez,项目名称:djanban,代码行数:22,代码来源:desktop_app_main.py

示例2: test_splitnport

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def test_splitnport(self):
        splitnport = urllib.splitnport
        self.assertEqual(splitnport('parrot:88'), ('parrot', 88))
        self.assertEqual(splitnport('parrot'), ('parrot', -1))
        self.assertEqual(splitnport('parrot', 55), ('parrot', 55))
        self.assertEqual(splitnport('parrot:'), ('parrot', -1))
        self.assertEqual(splitnport('parrot:', 55), ('parrot', 55))
        self.assertEqual(splitnport('127.0.0.1'), ('127.0.0.1', -1))
        self.assertEqual(splitnport('127.0.0.1', 55), ('127.0.0.1', 55))
        self.assertEqual(splitnport('parrot:cheese'), ('parrot', None))
        self.assertEqual(splitnport('parrot:cheese', 55), ('parrot', None)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_urllib.py

示例3: savefilename

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def savefilename(self, url):
        type, rest = urllib.splittype(url)
        host, path = urllib.splithost(rest)
        path = path.lstrip("/")
        user, host = urllib.splituser(host)
        host, port = urllib.splitnport(host)
        host = host.lower()
        if not path or path[-1] == "/":
            path = path + "index.html"
        if os.sep != "/":
            path = os.sep.join(path.split("/"))
        path = os.path.join(host, path)
        return path 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:15,代码来源:websucker.py

示例4: __init__

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def __init__(self, hub, url):
        self.hub = hub

        parsed = urlparse.urlsplit(url)
        assert parsed.query == ''
        assert parsed.fragment == ''

        default_port = 443 if parsed.scheme == 'https' else 80
        host, port = urllib.splitnport(parsed.netloc, default_port)

        self.socket = self.hub.tcp.connect(host=host, port=port)

        # TODO: this shouldn't block on the SSL handshake
        if parsed.scheme == 'https':
            # TODO: what a mess
            conn = self.socket.sender.fd.conn
            conn = ssl.wrap_socket(conn)
            conn.setblocking(0)
            self.socket.sender.fd.conn = conn

        self.socket.recver.sep = '\r\n'

        self.agent = 'vanilla/%s' % vanilla.meta.__version__

        self.default_headers = dict([
            ('Accept', '*/*'),
            ('User-Agent', self.agent),
            ('Host', parsed.netloc), ])

        self.requests = self.hub.router().pipe(self.hub.queue(10))
        self.requests.pipe(self.hub.consumer(self.writer))

        self.responses = self.hub.router().pipe(self.hub.queue(10))
        self.responses.pipe(self.hub.consumer(self.reader)) 
开发者ID:cablehead,项目名称:vanilla,代码行数:36,代码来源:http.py

示例5: get_crawl_domain

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def get_crawl_domain(url):
	if isinstance(url, str):
		protocol, __ = urllib.splittype(url)
		host = urllib.splitnport(urllib.splithost(__)[0])
		return host[0] 
开发者ID:blackye,项目名称:luscan-devel,代码行数:7,代码来源:run.py

示例6: _parse_host

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitnport [as 别名]
def _parse_host (h, ) :
    if not h.startswith('serf://') :
        h = 'serf://%s' % h
    
    _parsed = list(urlparse.urlparse(h, ), )
    if _parsed[0] not in ('serf', ) :
        raise _exceptions.InvalidHostURL('invalid host url, `%s`.' % h, )

    # the `urlparse` module in `travis-cis` does not understand the
    # non-standard scheme like `serf'.
    _parsed[0] = 'http'
    if not _parsed[2].startswith('/') :
        _parsed[2] = '/' + _parsed[2]

    _parsed = urlparse.urlparse(urlparse.urlunparse(_parsed, ), )

    _host = map(
            lambda x : None if x in ('', -1, ) else x,
            urllib.splitnport(_parsed.netloc, defport=7373, ),
        )
    
    if not _host[0] and not _host[1] :
        raise _exceptions.InvalidHostURL('invalid host url, `%s`.' % h, )
    
    if not _host[0] :
        _host[0] = constant.DEFAULT_HOST
    
    if not _host[1] :
        _host[1] = constant.DEFAULT_PORT
    
    _queries = dict()
    if _parsed.query :
        _queries = dict(map(
                urllib.splitvalue,
                filter(string.strip, _parsed.query.split('&'), ),
            ), )
        if set(_queries.keys()) != AVAILABLE_HOST_URI_QUERY_KEYS :
            raise _exceptions.InvalidHostURL(
                    'unknown key found, %s' % list(
                        set(_queries.keys() - AVAILABLE_HOST_URI_QUERY_KEYS), ),
                )
    
    _host.append(_queries, )
    
    return _host 
开发者ID:spikeekips,项目名称:serf-python,代码行数:47,代码来源:connection.py


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