當前位置: 首頁>>代碼示例>>Python>>正文


Python client.InvalidURL方法代碼示例

本文整理匯總了Python中http.client.InvalidURL方法的典型用法代碼示例。如果您正苦於以下問題:Python client.InvalidURL方法的具體用法?Python client.InvalidURL怎麽用?Python client.InvalidURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在http.client的用法示例。


在下文中一共展示了client.InvalidURL方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_host_port

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_httplib.py

示例2: connect

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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) 
開發者ID:openstack,項目名稱:oslo.vmware,代碼行數:27,代碼來源:datastore.py

示例3: validate_server

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:30,代碼來源:phpgedviewconnector.py

示例4: test_prepare_url_with_invalid_host_arg_format

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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) 
開發者ID:slaily,項目名稱:pyhttptest,代碼行數:9,代碼來源:test_utils.py

示例5: test_prepare_url_with_not_supported_url_scheme

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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) 
開發者ID:slaily,項目名稱:pyhttptest,代碼行數:9,代碼來源:test_utils.py

示例6: prepare_url

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import InvalidURL [as 別名]
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 
開發者ID:slaily,項目名稱:pyhttptest,代碼行數:44,代碼來源:utils.py


注:本文中的http.client.InvalidURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。