API Reference

Module url_matcher

class Patterns(include: List[str], exclude: Union[List[str], NoneType] = None, priority: int = 500)[source]
__init__(include: List[str], exclude: Optional[List[str]] = None, priority: int = 500)[source]
all_includes_have_domain() bool[source]

Return true if all the include patterns have a domain

exclude: Tuple[str, ...]
get_domains() List[str][source]
get_includes_for(domain: str) List[str][source]
get_includes_without_domain() List[str][source]
include: Tuple[str, ...]
is_universal_pattern() bool[source]

Return true if there are no include patterns or they are empty. A universal pattern matches any domain

priority: int
class URLMatcher(data: Optional[Union[Mapping[Any, Patterns], Iterable[Tuple[Any, Patterns]]]] = None)[source]
__init__(data: Optional[Union[Mapping[Any, Patterns], Iterable[Tuple[Any, Patterns]]]] = None)[source]

A class that matches URLs against a list of patterns, returning the identifier of the rule that matched the URL.

Example usage:

matcher = URLMatcher()
matcher.add_or_update(1, Patterns(include=["example.com/product"]))
matcher.add_or_update(2, Patterns(include=["other.com"]))

assert matcher.match("http://example.com/product/a_product.html") == 1
assert matcher.match("http://other.com/a_different_page") == 2
Parameters:

data – A map or a list of tuples with identifier, patterns pairs to initialize the object from

add_or_update(identifier: Any, patterns: Patterns)[source]
get(identifier: Any) Optional[Patterns][source]
match(url: str) Optional[Any][source]
remove(identifier: Any)[source]