Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
__init__.py125 linesDownload Raw Back to pybase64
1from __future__ import annotations2 3from typing import TYPE_CHECKING4 5from ._license import _license6from ._version import _version7 8if TYPE_CHECKING:9    from ._typing import Buffer10 11try:12    from ._pybase64 import (13        _get_simd_flags_compile,  # noqa: F40114        _get_simd_flags_runtime,  # noqa: F40115        _get_simd_name,16        _get_simd_path,17        _set_simd_path,  # noqa: F40118        b64decode,19        b64decode_as_bytearray,20        b64encode,21        b64encode_as_string,22        encodebytes,23    )24except ImportError:25    from ._fallback import (26        _get_simd_name,27        _get_simd_path,28        b64decode,29        b64decode_as_bytearray,30        b64encode,31        b64encode_as_string,32        encodebytes,33    )34 35 36__all__ = (37    "b64decode",38    "b64decode_as_bytearray",39    "b64encode",40    "b64encode_as_string",41    "encodebytes",42    "standard_b64decode",43    "standard_b64encode",44    "urlsafe_b64decode",45    "urlsafe_b64encode",46)47 48__version__ = _version49 50 51def get_license_text() -> str:52    """Returns pybase64 license information as a :class:`str` object.53 54    The result includes libbase64 license information as well.55    """56    return _license57 58 59def get_version() -> str:60    """Returns pybase64 version as a :class:`str` object.61 62    The result reports if the C extension is used or not.63    e.g. `1.0.0 (C extension active - AVX2)`64    """65    simd_name = _get_simd_name(_get_simd_path())66    if simd_name != "fallback":67        return f"{__version__} (C extension active - {simd_name})"68    return f"{__version__} (C extension inactive)"69 70 71def standard_b64encode(s: Buffer) -> bytes:72    """Encode bytes using the standard Base64 alphabet.73 74    Argument ``s`` is a :term:`bytes-like object` to encode.75 76    The result is returned as a :class:`bytes` object.77    """78    return b64encode(s)79 80 81def standard_b64decode(s: str | Buffer) -> bytes:82    """Decode bytes encoded with the standard Base64 alphabet.83 84    Argument ``s`` is a :term:`bytes-like object` or ASCII string to85    decode.86 87    The result is returned as a :class:`bytes` object.88 89    A :exc:`binascii.Error` is raised if the input is incorrectly padded.90 91    Characters that are not in the standard alphabet are discarded prior92    to the padding check.93    """94    return b64decode(s)95 96 97def urlsafe_b64encode(s: Buffer) -> bytes:98    """Encode bytes using the URL- and filesystem-safe Base64 alphabet.99 100    Argument ``s`` is a :term:`bytes-like object` to encode.101 102    The result is returned as a :class:`bytes` object.103 104    The alphabet uses '-' instead of '+' and '_' instead of '/'.105    """106    return b64encode(s, b"-_")107 108 109def urlsafe_b64decode(s: str | Buffer) -> bytes:110    """Decode bytes using the URL- and filesystem-safe Base64 alphabet.111 112    Argument ``s`` is a :term:`bytes-like object` or ASCII string to113    decode.114 115    The result is returned as a :class:`bytes` object.116 117    A :exc:`binascii.Error` is raised if the input is incorrectly padded.118 119    Characters that are not in the URL-safe base-64 alphabet, and are not120    a plus '+' or slash '/', are discarded prior to the padding check.121 122    The alphabet uses '-' instead of '+' and '_' instead of '/'.123    """124    return b64decode(s, b"-_")125 
codekingpro/portable-devtools · Team Ai