本文整理汇总了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})
示例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))
示例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
示例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))
示例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]
示例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