PHP 8.2.30
Preview: utils.py Size: 2.36 KB
/opt/cloudlinux/venv/lib/python3.11/site-packages/isort/utils.py

import os
import sys
from pathlib import Path
from typing import Any, Dict, Optional, Tuple


class TrieNode:
    def __init__(self, config_file: str = "", config_data: Optional[Dict[str, Any]] = None) -> None:
        if not config_data:
            config_data = {}

        self.nodes: Dict[str, TrieNode] = {}
        self.config_info: Tuple[str, Dict[str, Any]] = (config_file, config_data)


class Trie:
    """
    A prefix tree to store the paths of all config files and to search the nearest config
    associated with each file
    """

    def __init__(self, config_file: str = "", config_data: Optional[Dict[str, Any]] = None) -> None:
        self.root: TrieNode = TrieNode(config_file, config_data)

    def insert(self, config_file: str, config_data: Dict[str, Any]) -> None:
        resolved_config_path_as_tuple = Path(config_file).parent.resolve().parts

        temp = self.root

        for path in resolved_config_path_as_tuple:
            if path not in temp.nodes:
                temp.nodes[path] = TrieNode()

            temp = temp.nodes[path]

        temp.config_info = (config_file, config_data)

    def search(self, filename: str) -> Tuple[str, Dict[str, Any]]:
        """
        Returns the closest config relative to filename by doing a depth
        first search on the prefix tree.
        """
        resolved_file_path_as_tuple = Path(filename).resolve().parts

        temp = self.root

        last_stored_config: Tuple[str, Dict[str, Any]] = ("", {})

        for path in resolved_file_path_as_tuple:
            if temp.config_info[0]:
                last_stored_config = temp.config_info

            if path not in temp.nodes:
                break

            temp = temp.nodes[path]

        return last_stored_config


def exists_case_sensitive(path: str) -> bool:
    """Returns if the given path exists and also matches the case on Windows.

    When finding files that can be imported, it is important for the cases to match because while
    file os.path.exists("module.py") and os.path.exists("MODULE.py") both return True on Windows,
    Python can only import using the case of the real file.
    """
    result = os.path.exists(path)
    if (sys.platform.startswith("win") or sys.platform == "darwin") and result:  # pragma: no cover
        directory, basename = os.path.split(path)
        result = basename in os.listdir(directory)
    return result

Directory Contents

Dirs: 4 × Files: 28

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
stdlibs DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
_vendored DIR
- drwxr-xr-x 2026-01-20 13:01:48
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
25.51 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
933 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
22.00 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
6.89 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.55 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.35 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
8.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.16 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.63 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
388 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
45.73 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
27.15 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
24.74 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.05 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.09 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
0 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.28 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
297 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
34.75 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.24 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.41 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.36 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
6.17 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
13.25 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
72 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
871 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
36 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download

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