Python urllib.splitnport() Examples
The following are 11
code examples of urllib.splitnport().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urllib
, or try the search function
.
Example #1
Source File: desktop_app_main.py From djanban with MIT License | 6 votes |
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})
Example #2
Source File: test_urllib.py From ironpython2 with Apache License 2.0 | 5 votes |
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))
Example #3
Source File: websucker.py From oss-ftp with MIT License | 5 votes |
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
Example #4
Source File: test_urllib.py From oss-ftp with MIT License | 5 votes |
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))
Example #5
Source File: http.py From vanilla with MIT License | 5 votes |
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))
Example #6
Source File: run.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def get_crawl_domain(url): if isinstance(url, str): protocol, __ = urllib.splittype(url) host = urllib.splitnport(urllib.splithost(__)[0]) return host[0]
Example #7
Source File: test_urllib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example #8
Source File: websucker.py From datafari with Apache License 2.0 | 5 votes |
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
Example #9
Source File: test_urllib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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))
Example #10
Source File: test_urllib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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))
Example #11
Source File: connection.py From serf-python with Mozilla Public License 2.0 | 4 votes |
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