OXIESEC PANEL
- Current Dir:
/
/
opt
/
cloudlinux
/
venv
/
lib
/
python3.11
/
site-packages
/
isort
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
09/05/2025 09:34:06 AM
rwxr-xr-x
📄
__init__.py
871 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
__main__.py
36 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📁
__pycache__
-
02/07/2025 10:01:30 PM
rwxr-xr-x
📁
_vendored
-
12/18/2024 10:23:16 AM
rwxr-xr-x
📄
_version.py
72 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
api.py
25.51 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
comments.py
933 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
core.py
22 KB
12/18/2024 10:23:16 AM
rw-r--r--
📁
deprecated
-
02/07/2025 10:01:30 PM
rwxr-xr-x
📄
exceptions.py
6.89 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
files.py
1.55 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
format.py
5.35 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
hooks.py
3.26 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
identify.py
8.18 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
io.py
2.16 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
literal.py
3.63 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
logo.py
388 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
main.py
45.73 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
output.py
27.15 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
parse.py
24.74 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
place.py
5.05 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
profiles.py
2.09 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
py.typed
0 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
pylama_isort.py
1.28 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
sections.py
297 bytes
12/18/2024 10:23:16 AM
rw-r--r--
📄
settings.py
34.75 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
setuptools_commands.py
2.24 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
sorting.py
4.41 KB
12/18/2024 10:23:16 AM
rw-r--r--
📁
stdlibs
-
02/07/2025 10:01:30 PM
rwxr-xr-x
📄
utils.py
2.36 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
wrap.py
6.17 KB
12/18/2024 10:23:16 AM
rw-r--r--
📄
wrap_modes.py
13.25 KB
12/18/2024 10:23:16 AM
rw-r--r--
Editing: literal.py
Close
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))))