Skip to content

route_rules.export ¤

Classes:

Exporter ¤

Bases: ABC

Parameters:

  • export_path_template (str) –

Methods:

Attributes:

export_path_template class-attribute instance-attribute ¤

export_path_template: str = field(kw_only=True)

export abstractmethod ¤

export(file: str | PathLike[str], ruleset: RuleSet) -> int
Source code in src/route_rules/export/_abc.py
14
15
16
@abc.abstractmethod
def export(self, file: str | os.PathLike[str], ruleset: RuleSet) -> int:
    raise NotImplementedError

export_path ¤

export_path(slug: str) -> Path
Source code in src/route_rules/export/_abc.py
18
19
def export_path(self, slug: str) -> Path:
    return Path(self.export_path_template.format(slug=slug))

ExporterMihomo ¤

Bases: Exporter

Parameters:

  • behavior (Behavior) –
  • format (Format) –
  • export_path_template (str, default: 'mihomo/{slug}.{behavior}{format.ext}' ) –

Methods:

Attributes:

behavior class-attribute instance-attribute ¤

behavior: Behavior = field()

export_path_template class-attribute instance-attribute ¤

export_path_template: str = field(
    default="mihomo/{slug}.{behavior}{format.ext}",
    kw_only=True,
)

format class-attribute instance-attribute ¤

format: Format = field()

export ¤

export(file: str | PathLike[str], ruleset: RuleSet) -> int
Source code in src/route_rules/export/_mihomo.py
25
26
27
28
29
30
31
32
33
34
35
36
37
@override
def export(
    self,
    file: str | os.PathLike[str],
    ruleset: RuleSet,
) -> int:
    data: bytes = encode(ruleset, behavior=self.behavior, format=self.format)
    if not data:
        return 0
    file = Path(file)
    file.parent.mkdir(parents=True, exist_ok=True)
    file.write_bytes(data)
    return len(data)

export_path ¤

export_path(slug: str) -> Path
Source code in src/route_rules/export/_mihomo.py
39
40
41
42
43
44
45
@override
def export_path(self, slug: str) -> Path:
    return Path(
        self.export_path_template.format(
            slug=slug, behavior=self.behavior, format=self.format
        )
    )