本文整理汇总了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;未经允许,请勿转载。 |
请发表评论