[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.220.222.188: ~ $
"""
Helpers for normalization as expected in wheel/sdist/module file names
and core metadata
"""
import re
from pathlib import Path
from typing import Union

from .extern import packaging

_Path = Union[str, Path]

# https://packaging.python.org/en/latest/specifications/core-metadata/#name
_VALID_NAME = re.compile(r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.I)
_UNSAFE_NAME_CHARS = re.compile(r"[^A-Z0-9.]+", re.I)
_NON_ALPHANUMERIC = re.compile(r"[^A-Z0-9]+", re.I)
_PEP440_FALLBACK = re.compile(r"^v?(?P<safe>(?:[0-9]+!)?[0-9]+(?:\.[0-9]+)*)", re.I)


def safe_identifier(name: str) -> str:
    """Make a string safe to be used as Python identifier.
    >>> safe_identifier("12abc")
    '_12abc'
    >>> safe_identifier("__editable__.myns.pkg-78.9.3_local")
    '__editable___myns_pkg_78_9_3_local'
    """
    safe = re.sub(r'\W|^(?=\d)', '_', name)
    assert safe.isidentifier()
    return safe


def safe_name(component: str) -> str:
    """Escape a component used as a project name according to Core Metadata.
    >>> safe_name("hello world")
    'hello-world'
    >>> safe_name("hello?world")
    'hello-world'
    """
    # See pkg_resources.safe_name
    return _UNSAFE_NAME_CHARS.sub("-", component)


def safe_version(version: str) -> str:
    """Convert an arbitrary string into a valid version string.
    Can still raise an ``InvalidVersion`` exception.
    To avoid exceptions use ``best_effort_version``.
    >>> safe_version("1988 12 25")
    '1988.12.25'
    >>> safe_version("v0.2.1")
    '0.2.1'
    >>> safe_version("v0.2?beta")
    '0.2b0'
    >>> safe_version("v0.2 beta")
    '0.2b0'
    >>> safe_version("ubuntu lts")
    Traceback (most recent call last):
    ...
    setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'ubuntu.lts'
    """
    v = version.replace(' ', '.')
    try:
        return str(packaging.version.Version(v))
    except packaging.version.InvalidVersion:
        attempt = _UNSAFE_NAME_CHARS.sub("-", v)
        return str(packaging.version.Version(attempt))


def best_effort_version(version: str) -> str:
    """Convert an arbitrary string into a version-like string.
    Fallback when ``safe_version`` is not safe enough.
    >>> best_effort_version("v0.2 beta")
    '0.2b0'
    >>> best_effort_version("ubuntu lts")
    '0.dev0+sanitized.ubuntu.lts'
    >>> best_effort_version("0.23ubuntu1")
    '0.23.dev0+sanitized.ubuntu1'
    >>> best_effort_version("0.23-")
    '0.23.dev0+sanitized'
    >>> best_effort_version("0.-_")
    '0.dev0+sanitized'
    >>> best_effort_version("42.+?1")
    '42.dev0+sanitized.1'
    """
    # See pkg_resources._forgiving_version
    try:
        return safe_version(version)
    except packaging.version.InvalidVersion:
        v = version.replace(' ', '.')
        match = _PEP440_FALLBACK.search(v)
        if match:
            safe = match["safe"]
            rest = v[len(safe) :]
        else:
            safe = "0"
            rest = version
        safe_rest = _NON_ALPHANUMERIC.sub(".", rest).strip(".")
        local = f"sanitized.{safe_rest}".strip(".")
        return safe_version(f"{safe}.dev0+{local}")


def safe_extra(extra: str) -> str:
    """Normalize extra name according to PEP 685
    >>> safe_extra("_FrIeNdLy-._.-bArD")
    'friendly-bard'
    >>> safe_extra("FrIeNdLy-._.-bArD__._-")
    'friendly-bard'
    """
    return _NON_ALPHANUMERIC.sub("-", extra).strip("-").lower()


def filename_component(value: str) -> str:
    """Normalize each component of a filename (e.g. distribution/version part of wheel)
    Note: ``value`` needs to be already normalized.
    >>> filename_component("my-pkg")
    'my_pkg'
    """
    return value.replace("-", "_").strip("_")


def safer_name(value: str) -> str:
    """Like ``safe_name`` but can be used as filename component for wheel"""
    # See bdist_wheel.safer_name
    return filename_component(safe_name(value))


def safer_best_effort_version(value: str) -> str:
    """Like ``best_effort_version`` but can be used as filename component for wheel"""
    # See bdist_wheel.safer_verion
    # TODO: Replace with only safe_version in the future (no need for best effort)
    return filename_component(best_effort_version(value))

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
_distutils Folder 0755
_vendor Folder 0755
command Folder 0755
config Folder 0755
extern Folder 0755
__init__.py File 9 KB 0644
_core_metadata.py File 8.71 KB 0644
_entry_points.py File 2.18 KB 0644
_imp.py File 2.38 KB 0644
_importlib.py File 1.43 KB 0644
_itertools.py File 675 B 0644
_normalization.py File 4.12 KB 0644
_path.py File 1.03 KB 0644
_reqs.py File 1.09 KB 0644
archive_util.py File 7.16 KB 0644
build_meta.py File 18.23 KB 0644
cli-32.exe File 11.5 KB 0644
cli-64.exe File 14 KB 0644
cli-arm64.exe File 13.5 KB 0644
cli.exe File 11.5 KB 0644
dep_util.py File 659 B 0644
depends.py File 5.45 KB 0644
discovery.py File 20.65 KB 0644
dist.py File 36.33 KB 0644
errors.py File 2.61 KB 0644
extension.py File 5.46 KB 0644
glob.py File 4.75 KB 0644
gui-32.exe File 11.5 KB 0644
gui-64.exe File 14 KB 0644
gui-arm64.exe File 13.5 KB 0644
gui.exe File 11.5 KB 0644
installer.py File 4.87 KB 0644
launch.py File 812 B 0644
logging.py File 1.21 KB 0644
modified.py File 190 B 0644
monkey.py File 4.67 KB 0644
msvc.py File 46.31 KB 0644
namespaces.py File 3 KB 0644
package_index.py File 37.45 KB 0644
py312compat.py File 330 B 0644
sandbox.py File 14.01 KB 0644
script (dev).tmpl File 218 B 0644
script.tmpl File 138 B 0644
unicode_utils.py File 941 B 0644
version.py File 161 B 0644
warnings.py File 3.61 KB 0644
wheel.py File 8.43 KB 0644
windows_support.py File 720 B 0644