def up(self): return urlmatch.UrlPattern("http://*.google.com/foo*bar")
def set(self, name: str, value: typing.Any, pattern: str = None) -> None: """Set a setting value in the config, optionally with a pattern.""" with self._handle_error('setting', name): urlpattern = urlmatch.UrlPattern(pattern) if pattern else None self._config.set_obj(name, value, pattern=urlpattern)
def _add_blocked(): for line in blocked_hosts: values.add(False, urlmatch.UrlPattern(line))
def test_get_obj_for_pattern_no_match(self, conf): pattern = urlmatch.UrlPattern('*://example.com') name = 'content.javascript.enabled' value = conf.get_obj_for_pattern(name, pattern=pattern) assert value is configutils.UNSET
def test_pattern_no_configapi(self, config_stub): pattern = urlmatch.UrlPattern('https://example.com/') with pytest.raises(TypeError, match="Can't use pattern without configapi!"): config.ConfigContainer(config_stub, pattern=pattern)
def _add_blocked(): with open(blocked_hosts, 'r', encoding='utf-8') as f: for line in f: values.add(False, urlmatch.UrlPattern(line))
def test_get_for_url(self, conf): """Test conf.get() with a URL/pattern.""" pattern = urlmatch.UrlPattern('*://example.com/') name = 'content.javascript.enabled' conf.set_obj(name, False, pattern=pattern) assert conf.get(name, url=QUrl('https://example.com/')) is False
def test_special_schemes(pattern, url, expected): assert urlmatch.UrlPattern(pattern).matches(QUrl(url)) == expected
def up(self, request): return urlmatch.UrlPattern(request.param)
def test_attrs_wildcard(self): up = urlmatch.UrlPattern('*://*/*') assert up._match_subdomains assert not up._match_all
def test_attrs_all(self): up = urlmatch.UrlPattern('<all_urls>') assert not up._match_subdomains assert up._match_all
def up(self): return urlmatch.UrlPattern("chrome://favicon/*")
def test_urls(self, pattern, expected): up = urlmatch.UrlPattern(pattern) assert up.matches(QUrl("http://127.0.0.1")) == expected
def up(self): return urlmatch.UrlPattern(r"file:///foo-bar\*baz")
def test_str(): text = 'https://www.example.com/' pat = urlmatch.UrlPattern(text) assert str(pat) == text
def up(self): return urlmatch.UrlPattern("http://www.example.com:*/foo")
def test_should_use_pdfjs_url_pattern(config_stub, url, expected): config_stub.val.content.pdfjs = False pattern = urlmatch.UrlPattern('http://example.com') config_stub.set_obj('content.pdfjs', True, pattern=pattern) assert pdfjs.should_use_pdfjs('application/pdf', QUrl(url)) == expected
def test_trailing_slash(): """Contrary to Chromium, we allow to leave off a trailing slash.""" url = QUrl('http://www.example.com/') pattern = urlmatch.UrlPattern('http://www.example.com') assert pattern.matches(url)
def other_pattern(): return urlmatch.UrlPattern('https://www.example.org/')
def run(): up = urlmatch.UrlPattern('https://*.example.com/*foo*') up.matches(url)
def test_get_obj_for_pattern(self, conf): pattern = urlmatch.UrlPattern('*://example.com') name = 'content.javascript.enabled' conf.set_obj(name, False, pattern=pattern) assert conf.get_obj_for_pattern(name, pattern=pattern) is False
def test_urlpattern_hypothesis(pattern): try: up = urlmatch.UrlPattern(pattern) except urlmatch.ParseError: return up.matches(QUrl('https://www.example.com/'))
def test_set_no_pattern(self, conf, method, qtbot): meth = getattr(conf, method) pattern = urlmatch.UrlPattern('https://www.example.com/') with pytest.raises(configexc.NoPatternError): with qtbot.assert_not_emitted(conf.changed): meth('colors.statusbar.normal.bg', '#abcdef', pattern=pattern)
def test_equal(text1, text2, equal): pat1 = urlmatch.UrlPattern(text1) pat2 = urlmatch.UrlPattern(text2) assert (pat1 == pat2) == equal assert (hash(pat1) == hash(pat2)) == equal
def get(self, name: str, pattern: str = None) -> typing.Any: """Get a setting value from the config, optionally with a pattern.""" with self._handle_error('getting', name): urlpattern = urlmatch.UrlPattern(pattern) if pattern else None return self._config.get_mutable_obj(name, pattern=urlpattern)
def test_equal_string(): assert urlmatch.UrlPattern("<all_urls>") != '<all_urls>'
def test_get_multiple_matches(values): """With multiple matching pattern, the last added should win.""" all_pattern = urlmatch.UrlPattern('*://*/') values.add('new value', all_pattern) url = QUrl('https://www.example.com/') assert values.get_for_url(url) == 'new value'
def test_repr(): pat = urlmatch.UrlPattern('https://www.example.com/') expected = ("qutebrowser.utils.urlmatch.UrlPattern(" "pattern='https://www.example.com/')") assert repr(pat) == expected
def pattern(): return urlmatch.UrlPattern('*://www.example.com/')
def up(self): return urlmatch.UrlPattern("https://*/foo*")