當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。