当前位置: 首页>>代码示例>>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;未经允许,请勿转载。