• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.raises函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qutebrowser.utils.utils.raises函数的典型用法代码示例。如果您正苦于以下问题:Python raises函数的具体用法?Python raises怎么用?Python raises使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了raises函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _is_url_naive

def _is_url_naive(urlstr):
    """Naive check if given URL is really a URL.

    Args:
        urlstr: The URL to check for, as string.

    Return:
        True if the URL really is a URL, False otherwise.
    """
    url = qurl_from_user_input(urlstr)
    try:
        ipaddress.ip_address(urlstr)
    except ValueError:
        pass
    else:
        # Valid IPv4/IPv6 address
        return True

    # Qt treats things like "23.42" or "1337" or "0xDEAD" as valid URLs
    # which we don't want to. Note we already filtered *real* valid IPs
    # above.
    if ((not utils.raises(ValueError, int, urlstr, 0)) or
            (not utils.raises(ValueError, float, urlstr))):
        return False

    if not url.isValid():
        return False
    elif '.' in url.host():
        return True
    elif url.host() == 'localhost':
        return True
    else:
        return False
开发者ID:HalosGhost,项目名称:qutebrowser,代码行数:33,代码来源:urlutils.py


示例2: _is_url_dns

def _is_url_dns(urlstr):
    """Check if a URL is really a URL via DNS.

    Args:
        url: The URL to check for as a string.

    Return:
        True if the URL really is a URL, False otherwise.
    """
    url = qurl_from_user_input(urlstr)
    assert url.isValid()

    if (utils.raises(ValueError, ipaddress.ip_address, urlstr) and
            not QHostAddress(urlstr).isNull()):
        log.url.debug("Bogus IP URL -> False")
        # Qt treats things like "23.42" or "1337" or "0xDEAD" as valid URLs
        # which we don't want to.
        return False

    host = url.host()
    if not host:
        log.url.debug("URL has no host -> False")
        return False
    log.url.debug("Doing DNS request for {}".format(host))
    info = QHostInfo.fromName(host)
    return not info.error()
开发者ID:michaelbeaumont,项目名称:qutebrowser,代码行数:26,代码来源:urlutils.py


示例3: _is_url_naive

def _is_url_naive(urlstr):
    """Naive check if given URL is really a URL.

    Args:
        urlstr: The URL to check for, as string.

    Return:
        True if the URL really is a URL, False otherwise.
    """
    url = qurl_from_user_input(urlstr)
    assert url.isValid()

    if not utils.raises(ValueError, ipaddress.ip_address, urlstr):
        # Valid IPv4/IPv6 address
        return True

    # Qt treats things like "23.42" or "1337" or "0xDEAD" as valid URLs
    # which we don't want to. Note we already filtered *real* valid IPs
    # above.
    if not QHostAddress(urlstr).isNull():
        return False

    if '.' in url.host():
        return True
    else:
        return False
开发者ID:ProtractorNinja,项目名称:qutebrowser,代码行数:26,代码来源:urlutils.py


示例4: _matches_host

    def _matches_host(self, host):
        # FIXME what about multiple dots?
        host = host.rstrip('.')

        # If we have no host in the match pattern, that means that we're
        # matching all hosts, which means we have a match no matter what the
        # test host is.
        # Contrary to Chromium, we don't need to check for
        # self._match_subdomains, as we want to return True here for e.g.
        # file:// as well.
        if self._host is None:
            return True

        # If the hosts are exactly equal, we have a match.
        if host == self._host:
            return True

        # Otherwise, we can only match if our match pattern matches subdomains.
        if not self._match_subdomains:
            return False

        # We don't do subdomain matching against IP addresses, so we can give
        # up now if the test host is an IP address.
        if not utils.raises(ValueError, ipaddress.ip_address, host):
            return False

        # Check if the test host is a subdomain of our host.
        if len(host) <= (len(self._host) + 1):
            return False

        if not host.endswith(self._host):
            return False

        return host[len(host) - len(self._host) - 1] == '.'
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:34,代码来源:urlmatch.py


示例5: test_unrelated_exception

 def test_unrelated_exception(self):
     """Test with an unrelated exception."""
     with pytest.raises(Exception):
         utils.raises(ValueError, self.do_raise)
开发者ID:andor44,项目名称:qutebrowser,代码行数:4,代码来源:test_utils.py


示例6: test_no_args_false

 def test_no_args_false(self):
     """Test with no args and an exception which does not get raised."""
     assert not utils.raises(Exception, self.do_nothing)
开发者ID:andor44,项目名称:qutebrowser,代码行数:3,代码来源:test_utils.py


示例7: test_no_args_true

 def test_no_args_true(self):
     """Test with no args and an exception which gets raised."""
     assert utils.raises(Exception, self.do_raise)
开发者ID:andor44,项目名称:qutebrowser,代码行数:3,代码来源:test_utils.py


示例8: test_raises_multiple_exc_false

 def test_raises_multiple_exc_false(self):
     """Test raises with multiple exceptions which do not get raised."""
     assert not utils.raises((ValueError, TypeError), int, '1')
开发者ID:andor44,项目名称:qutebrowser,代码行数:3,代码来源:test_utils.py


示例9: test_raises_multiple_exc_true

 def test_raises_multiple_exc_true(self):
     """Test raises with multiple exceptions which get raised."""
     assert utils.raises((ValueError, TypeError), int, 'a')
     assert utils.raises((ValueError, TypeError), int, None)
开发者ID:andor44,项目名称:qutebrowser,代码行数:4,代码来源:test_utils.py


示例10: test_raises_single_exc_false

 def test_raises_single_exc_false(self):
     """Test raises with a single exception which does not get raised."""
     assert not utils.raises(ValueError, int, '1')
开发者ID:andor44,项目名称:qutebrowser,代码行数:3,代码来源:test_utils.py


示例11: test_raises_single_exc_true

 def test_raises_single_exc_true(self):
     """Test raises with a single exception which gets raised."""
     assert utils.raises(ValueError, int, 'a')
开发者ID:andor44,项目名称:qutebrowser,代码行数:3,代码来源:test_utils.py



注:本文中的qutebrowser.utils.utils.raises函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.read_file函数代码示例发布时间:2022-05-26
下一篇:
Python utils.qualname函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap