PHP 8.2.30
Preview: utils.py Size: 1.26 KB
/proc/thread-self/root/opt/cloudlinux/venv/lib/python3.11/site-packages/pydocstyle/utils.py

"""General shared utilities."""
import logging
import re
from itertools import tee, zip_longest
from typing import Any, Iterable, Tuple

# Do not update the version manually - it is managed by `bumpversion`.
log = logging.getLogger(__name__)

#: Regular expression for stripping non-alphanumeric characters
NON_ALPHANUMERIC_STRIP_RE = re.compile(r'[\W_]+')


def is_blank(string: str) -> bool:
    """Return True iff the string contains only whitespaces."""
    return not string.strip()


def pairwise(
    iterable: Iterable,
    default_value: Any,
) -> Iterable[Tuple[Any, Any]]:
    """Return pairs of items from `iterable`.

    pairwise([1, 2, 3], default_value=None) -> (1, 2) (2, 3), (3, None)
    """
    a, b = tee(iterable)
    _ = next(b, default_value)
    return zip_longest(a, b, fillvalue=default_value)


def common_prefix_length(a: str, b: str) -> int:
    """Return the length of the longest common prefix of a and b.

    >>> common_prefix_length('abcd', 'abce')
    3

    """
    for common, (ca, cb) in enumerate(zip(a, b)):
        if ca != cb:
            return common
    return min(len(a), len(b))


def strip_non_alphanumeric(string: str) -> str:
    """Strip string from any non-alphanumeric characters."""
    return NON_ALPHANUMERIC_STRIP_RE.sub('', string)

Directory Contents

Dirs: 2 × Files: 10

Name Size Perms Modified Actions
data DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
43.83 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.92 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
32.70 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
27.63 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.26 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
12.12 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.51 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
400 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
194 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
288 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download

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