Ejemplo n.º 1
0
 def up(self):
     return urlmatch.UrlPattern("http://*.google.com/foo*bar")
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def _add_blocked():
     for line in blocked_hosts:
         values.add(False, urlmatch.UrlPattern(line))
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def _add_blocked():
     with open(blocked_hosts, 'r', encoding='utf-8') as f:
         for line in f:
             values.add(False, urlmatch.UrlPattern(line))
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
def test_special_schemes(pattern, url, expected):
    assert urlmatch.UrlPattern(pattern).matches(QUrl(url)) == expected
Ejemplo n.º 9
0
 def up(self, request):
     return urlmatch.UrlPattern(request.param)
Ejemplo n.º 10
0
 def test_attrs_wildcard(self):
     up = urlmatch.UrlPattern('*://*/*')
     assert up._match_subdomains
     assert not up._match_all
Ejemplo n.º 11
0
 def test_attrs_all(self):
     up = urlmatch.UrlPattern('<all_urls>')
     assert not up._match_subdomains
     assert up._match_all
Ejemplo n.º 12
0
 def up(self):
     return urlmatch.UrlPattern("chrome://favicon/*")
Ejemplo n.º 13
0
 def test_urls(self, pattern, expected):
     up = urlmatch.UrlPattern(pattern)
     assert up.matches(QUrl("http://127.0.0.1")) == expected
Ejemplo n.º 14
0
 def up(self):
     return urlmatch.UrlPattern(r"file:///foo-bar\*baz")
Ejemplo n.º 15
0
def test_str():
    text = 'https://www.example.com/'
    pat = urlmatch.UrlPattern(text)
    assert str(pat) == text
Ejemplo n.º 16
0
 def up(self):
     return urlmatch.UrlPattern("http://www.example.com:*/foo")
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
def other_pattern():
    return urlmatch.UrlPattern('https://www.example.org/')
Ejemplo n.º 20
0
 def run():
     up = urlmatch.UrlPattern('https://*.example.com/*foo*')
     up.matches(url)
Ejemplo n.º 21
0
 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
Ejemplo n.º 22
0
def test_urlpattern_hypothesis(pattern):
    try:
        up = urlmatch.UrlPattern(pattern)
    except urlmatch.ParseError:
        return
    up.matches(QUrl('https://www.example.com/'))
Ejemplo n.º 23
0
 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)
Ejemplo n.º 24
0
def test_equal(text1, text2, equal):
    pat1 = urlmatch.UrlPattern(text1)
    pat2 = urlmatch.UrlPattern(text2)

    assert (pat1 == pat2) == equal
    assert (hash(pat1) == hash(pat2)) == equal
Ejemplo n.º 25
0
 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)
Ejemplo n.º 26
0
def test_equal_string():
    assert urlmatch.UrlPattern("<all_urls>") != '<all_urls>'
Ejemplo n.º 27
0
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'
Ejemplo n.º 28
0
def test_repr():
    pat = urlmatch.UrlPattern('https://www.example.com/')
    expected = ("qutebrowser.utils.urlmatch.UrlPattern("
                "pattern='https://www.example.com/')")
    assert repr(pat) == expected
Ejemplo n.º 29
0
def pattern():
    return urlmatch.UrlPattern('*://www.example.com/')
Ejemplo n.º 30
0
 def up(self):
     return urlmatch.UrlPattern("https://*/foo*")