Skip to content

route_rules.core ¤

Classes:

Recipe ¤

Parameters:

  • name (str) –
  • providers (list[str]) –
  • registry (ProviderRegistry, default: ProviderRegistry(registry={'blackmatrix7': ProviderMihomo(name='blackmatrix7', download_url_template='https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/{name}/{name}.list', preview_url_template='https://github.com/blackmatrix7/ios_rule_script/tree/master/rule/Clash/{name}', _cache=LRUCache({}, maxsize=65536, currsize=0), behavior=<Behavior.CLASSICAL: 'classical'>, format=<Format.TEXT: 'text'>), 'dler-io': ProviderMihomo(name='dler-io', download_url_template='https://raw.githubusercontent.com/dler-io/Rules/main/Clash/Provider/{name}.yaml', preview_url_template='https://github.com/dler-io/Rules/blob/main/Clash/Provider/{name}.yaml', _cache=LRUCache({}, maxsize=65536, currsize=0), behavior=<Behavior.CLASSICAL: 'classical'>, format=<Format.YAML: 'yaml'>), 'MetaCubeX/geosite': ProviderMihomo(name='MetaCubeX/geosite', download_url_template='https://raw.githubusercontent.com/MetaCubeX/meta-rules-dat/meta/geo/geosite/{name}.yaml', preview_url_template='https://github.com/MetaCubeX/meta-rules-dat/blob/meta/geo/geosite/{name}.yaml', _cache=LRUCache({}, maxsize=65536, currsize=0), behavior=<Behavior.DOMAIN: 'domain'>, format=<Format.YAML: 'yaml'>), 'SukkaW/classical': ProviderMihomo(name='SukkaW/classical', download_url_template='https://ruleset.skk.moe/Clash/{name}.txt', preview_url_template='https://ruleset.skk.moe/Clash/{name}.txt', _cache=LRUCache({}, maxsize=65536, currsize=0), behavior=<Behavior.CLASSICAL: 'classical'>, format=<Format.TEXT: 'text'>), 'SukkaW/domain': ProviderMihomo(name='SukkaW/domain', download_url_template='https://ruleset.skk.moe/Clash/{name}.txt', preview_url_template='https://ruleset.skk.moe/Clash/{name}.txt', _cache=LRUCache({}, maxsize=65536, currsize=0), behavior=<Behavior.DOMAIN: 'domain'>, format=<Format.TEXT: 'text'>)}) ) –
  • slug (str, default: <dynamic> ) –

Methods:

Attributes:

name class-attribute instance-attribute ¤

name: str = field()

providers class-attribute instance-attribute ¤

providers: list[str] = field()

registry class-attribute instance-attribute ¤

registry: ProviderRegistry = field(
    factory=presets, kw_only=True
)

slug class-attribute instance-attribute ¤

slug: str = field(
    default=Factory(default_slug, takes_self=True),
    kw_only=True,
)

build async ¤

build() -> RuleSet
Source code in src/route_rules/core/_recipe.py
28
29
30
31
32
33
34
@cta.cachedmethod(lambda self: self._cache)
async def build(self) -> RuleSet:
    ruleset: RuleSet = RuleSet.union(
        *(await asyncio.gather(*(self.registry.load(p) for p in self.providers)))
    )
    ruleset = ruleset.optimize()
    return ruleset

RuleSet ¤

Bases: UserDict[str, set[str]]

.

References
  1. https://wiki.metacubex.one/en/config/rules/

Methods:

Attributes:

domain property ¤

domain: set[str]

domain_suffix property ¤

domain_suffix: set[str]

ip_cidr property ¤

ip_cidr: set[str]

__missing__ ¤

__missing__(key: str) -> set[str]
Source code in src/route_rules/core/_ruleset.py
21
22
23
def __missing__(self, key: str) -> set[str]:
    self[key] = set()
    return self[key]

__or__ ¤

__or__(other: Mapping[str, Set[str]]) -> Self
Source code in src/route_rules/core/_ruleset.py
14
15
16
17
18
19
@override
def __or__(self, other: Mapping[str, AbstractSet[str]], /) -> Self:  # pyright: ignore[reportIncompatibleMethodOverride]
    result: Self = type(self)()
    for typ in self.keys() | other.keys():
        result[typ] = self.get(typ, set()) | other.get(typ, set())
    return result

add ¤

add(typ: str, value: str) -> None
Source code in src/route_rules/core/_ruleset.py
37
38
39
40
41
def add(self, typ: str, value: str) -> None:
    # IP-CIDR and IP-CIDR6 have the same effect, with IP-CIDR6 being an alias.
    if typ == "IP-CIDR6":
        typ = "IP-CIDR"
    self[typ].add(value)

optimize ¤

optimize() -> Self
Source code in src/route_rules/core/_ruleset.py
43
44
45
def optimize(self) -> Self:
    # TODO: implement
    return self

union ¤

union(*others: Mapping[str, Set[str]]) -> Self
Source code in src/route_rules/core/_ruleset.py
47
48
49
50
51
52
53
def union(self, *others: Mapping[str, AbstractSet[str]]) -> Self:
    result: Self = type(self)()
    for typ in set(self.keys()).union(*(m.keys() for m in others)):
        result[typ] = self.get(typ, set()).union(
            *(m.get(typ, set()) for m in others)
        )
    return result