PHP 8.2.30
Preview: yaml_rewrite.py Size: 1.31 KB
//opt/hc_python/lib64/python3.12/site-packages/pre_commit/yaml_rewrite.py

from __future__ import annotations

from collections.abc import Generator
from collections.abc import Iterable
from typing import NamedTuple
from typing import Protocol

from yaml.nodes import MappingNode
from yaml.nodes import Node
from yaml.nodes import ScalarNode
from yaml.nodes import SequenceNode


class _Matcher(Protocol):
    def match(self, n: Node) -> Generator[Node]: ...


class MappingKey(NamedTuple):
    k: str

    def match(self, n: Node) -> Generator[Node]:
        if isinstance(n, MappingNode):
            for k, _ in n.value:
                if k.value == self.k:
                    yield k


class MappingValue(NamedTuple):
    k: str

    def match(self, n: Node) -> Generator[Node]:
        if isinstance(n, MappingNode):
            for k, v in n.value:
                if k.value == self.k:
                    yield v


class SequenceItem(NamedTuple):
    def match(self, n: Node) -> Generator[Node]:
        if isinstance(n, SequenceNode):
            yield from n.value


def _match(gen: Iterable[Node], m: _Matcher) -> Iterable[Node]:
    return (n for src in gen for n in m.match(src))


def match(n: Node, matcher: tuple[_Matcher, ...]) -> Generator[ScalarNode]:
    gen: Iterable[Node] = (n,)
    for m in matcher:
        gen = _match(gen, m)
    return (n for n in gen if isinstance(n, ScalarNode))

Directory Contents

Dirs: 5 × Files: 25

Name Size Perms Modified Actions
commands DIR
- drwxr-xr-x 2025-12-03 08:02:54
Edit Download
languages DIR
- drwxr-xr-x 2025-12-03 08:02:54
Edit Download
- drwxr-xr-x 2025-12-03 08:02:54
Edit Download
resources DIR
- drwxr-xr-x 2025-12-03 08:02:54
Edit Download
- drwxr-xr-x 2025-12-03 08:02:54
Edit Download
1.43 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
16.42 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
3.14 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
282 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
1.56 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
78 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
2.56 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
2.30 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
8.33 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
1.48 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
5.26 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
1019 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
15.54 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
911 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
2.42 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
495 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
7.43 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
4.06 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
8.27 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
6.88 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
5.42 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
561 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
1.31 KB lrw-r--r-- 2025-12-03 08:02:54
Edit Download
0 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download
127 B lrw-r--r-- 2025-12-03 08:02:54
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).