$87 GRAYBYTE WORDPRESS FILE MANAGER $76

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/cloudlinux/venv/lib/python3.11/site-packages/isort/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/isort//literal.py
import ast
from pprint import PrettyPrinter
from typing import Any, Callable, Dict, List, Set, Tuple

from isort.exceptions import (
    AssignmentsFormatMismatch,
    LiteralParsingFailure,
    LiteralSortTypeMismatch,
)
from isort.settings import DEFAULT_CONFIG, Config


class ISortPrettyPrinter(PrettyPrinter):
    """an isort customized pretty printer for sorted literals"""

    def __init__(self, config: Config):
        super().__init__(width=config.line_length, compact=True)


type_mapping: Dict[str, Tuple[type, Callable[[Any, ISortPrettyPrinter], str]]] = {}


def assignments(code: str) -> str:
    values = {}
    for line in code.splitlines(keepends=True):
        if not line.strip():
            continue
        if " = " not in line:
            raise AssignmentsFormatMismatch(code)
        variable_name, value = line.split(" = ", 1)
        values[variable_name] = value

    return "".join(
        f"{variable_name} = {values[variable_name]}" for variable_name in sorted(values.keys())
    )


def assignment(code: str, sort_type: str, extension: str, config: Config = DEFAULT_CONFIG) -> str:
    """Sorts the literal present within the provided code against the provided sort type,
    returning the sorted representation of the source code.
    """
    if sort_type == "assignments":
        return assignments(code)
    if sort_type not in type_mapping:
        raise ValueError(
            "Trying to sort using an undefined sort_type. "
            f"Defined sort types are {', '.join(type_mapping.keys())}."
        )

    variable_name, literal = code.split("=")
    variable_name = variable_name.strip()
    literal = literal.lstrip()
    try:
        value = ast.literal_eval(literal)
    except Exception as error:
        raise LiteralParsingFailure(code, error)

    expected_type, sort_function = type_mapping[sort_type]
    if type(value) != expected_type:
        raise LiteralSortTypeMismatch(type(value), expected_type)

    printer = ISortPrettyPrinter(config)
    sorted_value_code = f"{variable_name} = {sort_function(value, printer)}"
    if config.formatting_function:
        sorted_value_code = config.formatting_function(
            sorted_value_code, extension, config
        ).rstrip()

    sorted_value_code += code[len(code.rstrip()) :]
    return sorted_value_code


def register_type(
    name: str, kind: type
) -> Callable[[Callable[[Any, ISortPrettyPrinter], str]], Callable[[Any, ISortPrettyPrinter], str]]:
    """Registers a new literal sort type."""

    def wrap(
        function: Callable[[Any, ISortPrettyPrinter], str]
    ) -> Callable[[Any, ISortPrettyPrinter], str]:
        type_mapping[name] = (kind, function)
        return function

    return wrap


@register_type("dict", dict)
def _dict(value: Dict[Any, Any], printer: ISortPrettyPrinter) -> str:
    return printer.pformat(dict(sorted(value.items(), key=lambda item: item[1])))  # type: ignore


@register_type("list", list)
def _list(value: List[Any], printer: ISortPrettyPrinter) -> str:
    return printer.pformat(sorted(value))


@register_type("unique-list", list)
def _unique_list(value: List[Any], printer: ISortPrettyPrinter) -> str:
    return printer.pformat(list(sorted(set(value))))


@register_type("set", set)
def _set(value: Set[Any], printer: ISortPrettyPrinter) -> str:
    return "{" + printer.pformat(tuple(sorted(value)))[1:-1] + "}"


@register_type("tuple", tuple)
def _tuple(value: Tuple[Any, ...], printer: ISortPrettyPrinter) -> str:
    return printer.pformat(tuple(sorted(value)))


@register_type("unique-tuple", tuple)
def _unique_tuple(value: Tuple[Any, ...], printer: ISortPrettyPrinter) -> str:
    return printer.pformat(tuple(sorted(set(value))))

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
17 Dec 2025 3.08 AM
root / root
0755
__pycache__
--
14 Aug 2025 9.24 PM
root / root
0755
_vendored
--
17 Apr 2025 8.10 PM
root / root
0755
deprecated
--
14 Aug 2025 9.24 PM
root / root
0755
stdlibs
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
0.851 KB
17 Apr 2025 8.10 PM
root / root
0644
__main__.py
0.035 KB
17 Apr 2025 8.10 PM
root / root
0644
_version.py
0.07 KB
17 Apr 2025 8.10 PM
root / root
0644
api.py
25.508 KB
17 Apr 2025 8.10 PM
root / root
0644
comments.py
0.911 KB
17 Apr 2025 8.10 PM
root / root
0644
core.py
21.997 KB
17 Apr 2025 8.10 PM
root / root
0644
exceptions.py
6.895 KB
17 Apr 2025 8.10 PM
root / root
0644
files.py
1.552 KB
17 Apr 2025 8.10 PM
root / root
0644
format.py
5.354 KB
17 Apr 2025 8.10 PM
root / root
0644
hooks.py
3.26 KB
17 Apr 2025 8.10 PM
root / root
0644
identify.py
8.177 KB
17 Apr 2025 8.10 PM
root / root
0644
io.py
2.164 KB
17 Apr 2025 8.10 PM
root / root
0644
literal.py
3.626 KB
17 Apr 2025 8.10 PM
root / root
0644
logo.py
0.379 KB
17 Apr 2025 8.10 PM
root / root
0644
main.py
45.726 KB
17 Apr 2025 8.10 PM
root / root
0644
output.py
27.152 KB
17 Apr 2025 8.10 PM
root / root
0644
parse.py
24.738 KB
17 Apr 2025 8.10 PM
root / root
0644
place.py
5.05 KB
17 Apr 2025 8.10 PM
root / root
0644
profiles.py
2.094 KB
17 Apr 2025 8.10 PM
root / root
0644
py.typed
0 KB
17 Apr 2025 8.10 PM
root / root
0644
pylama_isort.py
1.277 KB
17 Apr 2025 8.10 PM
root / root
0644
sections.py
0.29 KB
17 Apr 2025 8.10 PM
root / root
0644
settings.py
34.75 KB
17 Apr 2025 8.10 PM
root / root
0644
setuptools_commands.py
2.243 KB
17 Apr 2025 8.10 PM
root / root
0644
sorting.py
4.409 KB
17 Apr 2025 8.10 PM
root / root
0644
utils.py
2.356 KB
17 Apr 2025 8.10 PM
root / root
0644
wrap.py
6.173 KB
17 Apr 2025 8.10 PM
root / root
0644
wrap_modes.py
13.251 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF