Python http.client.InvalidURL() Examples
The following are 13
code examples of http.client.InvalidURL().
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
http.client
, or try the search function
.
Example #1
Source File: test_httplib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:80", "www.python.org", 80), ("www.python.org:", "www.python.org", 80), ("www.python.org", "www.python.org", 80), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)): c = client.HTTPConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #2
Source File: test_httplib.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:443", "www.python.org", 443), ("www.python.org:", "www.python.org", 443), ("www.python.org", "www.python.org", 443), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 443)): c = client.HTTPSConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #3
Source File: test_httplib.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:80", "www.python.org", 80), ("www.python.org:", "www.python.org", 80), ("www.python.org", "www.python.org", 80), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)): c = client.HTTPConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #4
Source File: test_httplib.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:443", "www.python.org", 443), ("www.python.org:", "www.python.org", 443), ("www.python.org", "www.python.org", 443), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 443)): c = client.HTTPSConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #5
Source File: test_httplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:80", "www.python.org", 80), ("www.python.org:", "www.python.org", 80), ("www.python.org", "www.python.org", 80), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)): c = client.HTTPConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #6
Source File: test_httplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:443", "www.python.org", 443), ("www.python.org:", "www.python.org", 443), ("www.python.org", "www.python.org", 443), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 443)): c = client.HTTPSConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #7
Source File: datastore.py From oslo.vmware with Apache License 2.0 | 6 votes |
def connect(self, method, content_length, cookie): try: if self._scheme == 'http': conn = httplib.HTTPConnection(self._server) elif self._scheme == 'https': # TODO(browne): This needs to be changed to use python requests conn = httplib.HTTPSConnection(self._server) # nosec else: excep_msg = _("Invalid scheme: %s.") % self._scheme LOG.error(excep_msg) raise ValueError(excep_msg) conn.putrequest(method, '/folder/%s?%s' % (self.path, self._query)) conn.putheader('User-Agent', constants.USER_AGENT) conn.putheader('Content-Length', content_length) conn.putheader('Cookie', cookie) conn.endheaders() LOG.debug("Created HTTP connection to transfer the file with " "URL = %s.", str(self)) return conn except (httplib.InvalidURL, httplib.CannotSendRequest, httplib.CannotSendHeader) as excep: excep_msg = _("Error occurred while creating HTTP connection " "to write to file with URL = %s.") % str(self) LOG.exception(excep_msg) raise exceptions.VimConnectionException(excep_msg, excep)
Example #8
Source File: test_httplib.py From android_universal with MIT License | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:80", "www.python.org", 80), ("www.python.org:", "www.python.org", 80), ("www.python.org", "www.python.org", 80), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 80)): c = client.HTTPConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #9
Source File: test_httplib.py From android_universal with MIT License | 6 votes |
def test_host_port(self): # Check invalid host_port for hp in ("www.python.org:abc", "user:password@www.python.org"): self.assertRaises(client.InvalidURL, client.HTTPSConnection, hp) for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), ("www.python.org:443", "www.python.org", 443), ("www.python.org:", "www.python.org", 443), ("www.python.org", "www.python.org", 443), ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443), ("[fe80::207:e9ff:fe9b]:", "fe80::207:e9ff:fe9b", 443)): c = client.HTTPSConnection(hp) self.assertEqual(h, c.host) self.assertEqual(p, c.port)
Example #10
Source File: phpgedviewconnector.py From addons-source with GNU General Public License v2.0 | 5 votes |
def validate_server(self): try: self.update_progressbar(_("Connecting...")) self.connector = PHPGedViewConnector(self.url,self.update_progressbar) self.update_progressbar(_("Get version...")) version = self.connector.get_version() if version: self.version_label.set_text(_("Version %s") % version) self.update_progressbar(_("Reading file list...")) files = self.connector.list_gedcoms() list_store = self.file_combo.get_model() list_store.clear() for file in files: list_store.append([file[0],]) self.file_combo.show() self.username_entry.show() self.password_entry.show() return True except (ValueError, URLError, hcl.InvalidURL) as e: print(e) self.version_label.set_text(_("Error: Invalid URL")) self.update_progressbar(_("done.")) return False # TODO: This should go into PHPGedViewConnector
Example #11
Source File: test_utils.py From pyhttptest with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_prepare_url_with_invalid_host_arg_format(): with pytest.raises(InvalidURL) as exc: host = 'localhost.com' endpoint = 'users' utils.prepare_url(host, endpoint) assert 'Invalid URL' in str(exc.value)
Example #12
Source File: test_utils.py From pyhttptest with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_prepare_url_with_not_supported_url_scheme(): with pytest.raises(InvalidURL) as exc: host = 'ftp://localhost.com' endpoint = 'users' utils.prepare_url(host, endpoint) assert 'Invalid URL scheme' in str(exc.value)
Example #13
Source File: utils.py From pyhttptest with BSD 3-Clause "New" or "Revised" License | 4 votes |
def prepare_url(host, endpoint): """Glues the ``host`` and ``endpoint`` parameters to form an URL. :param str host: Value e.g. **http://localhost.com**. :param str endpoint: An API resourse e.g. **/users**. :raises InvalidURL: If the URL parts are in invalid format. :raises InvalidURL: If the URL schema is not supported. :returns: URL. :rtype: `str` """ if not host or not endpoint: return None if not host[-1] == '/' and not endpoint[0] == '/': url = '/'.join([host, endpoint]) if host[-1] == '/' and not endpoint[0] == '/': url = ''.join([host, endpoint]) if not host[-1] == '/' and endpoint[0] == '/': url = ''.join([host, endpoint]) if host[-1] == '/' and endpoint[0] == '/': url = ''.join([host, endpoint[1:]]) parsed_url = urlparse(url) if not parsed_url.scheme or not parsed_url.netloc: raise InvalidURL('Invalid URL {url}'.format(url=url)) if parsed_url.scheme not in ['http', 'https']: raise InvalidURL( 'Invalid URL scheme {scheme}. ' 'Supported schemes are http or https.'.format( scheme=parsed_url.scheme ) ) return url