Skip to content

route_rules.provider.mihomo ¤

Classes:

Functions:

Behavior ¤

Bases: StrEnum


              flowchart TD
              route_rules.provider.mihomo.Behavior[Behavior]

              

              click route_rules.provider.mihomo.Behavior href "" "route_rules.provider.mihomo.Behavior"
            

Attributes:

CLASSICAL class-attribute instance-attribute ¤

CLASSICAL = auto()

DOMAIN class-attribute instance-attribute ¤

DOMAIN = auto()

IPCIDR class-attribute instance-attribute ¤

IPCIDR = auto()

Format ¤

Bases: StrEnum


              flowchart TD
              route_rules.provider.mihomo.Format[Format]

              

              click route_rules.provider.mihomo.Format href "" "route_rules.provider.mihomo.Format"
            

Attributes:

MRS class-attribute instance-attribute ¤

MRS = auto()

TEXT class-attribute instance-attribute ¤

TEXT = auto()

YAML class-attribute instance-attribute ¤

YAML = auto()

ext property ¤

ext: str

ProviderMihomo ¤

Bases: Provider


              flowchart TD
              route_rules.provider.mihomo.ProviderMihomo[ProviderMihomo]
              route_rules.provider._abc.Provider[Provider]

                              route_rules.provider._abc.Provider --> route_rules.provider.mihomo.ProviderMihomo
                


              click route_rules.provider.mihomo.ProviderMihomo href "" "route_rules.provider.mihomo.ProviderMihomo"
              click route_rules.provider._abc.Provider href "" "route_rules.provider._abc.Provider"
            

Parameters:

  • name (str) –
  • download_url_template (str) –
  • preview_url_template (str, default: <dynamic> ) –
  • behavior (Behavior) –
  • format (Format, default: <Format.YAML: 'yaml'> ) –

Methods:

Attributes:

behavior class-attribute instance-attribute ¤

behavior: Behavior = field(kw_only=True)

download_url_template class-attribute instance-attribute ¤

download_url_template: str = field()

format class-attribute instance-attribute ¤

format: Format = field(default=YAML, kw_only=True)

name class-attribute instance-attribute ¤

name: str = field()

preview_url_template class-attribute instance-attribute ¤

preview_url_template: str = field(
    default=Factory(
        _default_preview_url_template, takes_self=True
    )
)

download_url ¤

download_url(name: str) -> str
Source code in src/route_rules/provider/_abc.py
26
27
28
def download_url(self, name: str) -> str:
    name = urllib.parse.quote(name)
    return self.download_url_template.format(name=name)

load async ¤

load(name: str) -> RuleSet
Source code in src/route_rules/provider/mihomo/_provider.py
20
21
22
23
24
25
@override
@cta.cachedmethod(lambda self: self._cache)
async def load(self, name: str) -> RuleSet:
    url: str = self.download_url(name)
    response: httpx.Response = await utils.download(url)
    return decode(response.text, behavior=self.behavior, format=self.format)

preview_url ¤

preview_url(name: str) -> str
Source code in src/route_rules/provider/_abc.py
34
35
36
def preview_url(self, name: str) -> str:
    name = urllib.parse.quote(name)
    return self.preview_url_template.format(name=name)

decode ¤

decode(
    data: str | bytes, behavior: Behavior, format: Format
) -> RuleSet
Source code in src/route_rules/provider/mihomo/_decode.py
15
16
17
18
def decode(data: str | bytes, behavior: Behavior, format: Format) -> RuleSet:  # noqa: A002
    payload: list[str] = _format_decoders[format](data)
    ruleset: RuleSet = _behavior_decoders[behavior](payload)
    return ruleset