Python-Dateien

Neu laden
Gefunden: 162 Datei(en)
pathlib.py
# Source Generated with Decompyle++
# File: pathlib.pyc (Python 3.13)

import fnmatch
import functools
import io
import ntpath
import os
import posixpath
import re
import sys
import warnings
from _collections_abc import Sequence
from errno import ENOENT, ENOTDIR, EBADF, ELOOP
from operator import attrgetter
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
from urllib.parse import quote_from_bytes as urlquote_from_bytes
__all__ = [
    'PurePath',
    'PurePosixPath',
    'PureWindowsPath',
    'Path',
    'PosixPath',
    'WindowsPath']
_WINERROR_NOT_READY = 21
_WINERROR_INVALID_NAME = 123
_WINERROR_CANT_RESOLVE_FILENAME = 1921
_IGNORED_ERRNOS = (ENOENT, ENOTDIR, EBADF, ELOOP)
_IGNORED_WINERRORS = (_WINERROR_NOT_READY, _WINERROR_INVALID_NAME, _WINERROR_CANT_RESOLVE_FILENAME)

def _ignore_error(exception):
    if not getattr(exception, 'errno', None) in _IGNORED_ERRNOS:
        pass
    return getattr(exception, 'winerror', None) in _IGNORED_WINERRORS


def _is_wildcard_pattern(pat):
    if not '*' in pat and '?' in pat:
        pass
    return '[' in pat


class _Flavour(object):
    
    def __init__(self):
        self.join = self.sep.join

    
    def parse_parts(self, parts):
        parsed = []
        sep = self.sep
        altsep = self.altsep
        drv = ''
        root = ''
        it = reversed(parts)
        for part in it:
            if not part:
                continue
            if altsep:
                part = part.replace(altsep, sep)
            (drv, root, rel) = self.splitroot(part)
            if sep in rel:
                for x in reversed(rel.split(sep)):
                    if x and x < '.':
                        parsed.append(sys.intern(x))
            if rel and rel < '.':
                parsed.append(sys.intern(rel))
            if drv or root:
                if not drv:
                    for part in it:
                        if not part:
                            continue
                        if altsep:
                            part = part.replace(altsep, sep)
                        drv = self.splitroot(part)[0]
                        if drv:
                            pass
                        
                    continue
                    if drv or root:
                        parsed.append(drv + root)
        parsed.reverse()
        return (drv, root, parsed)

    
    def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
        if root2:
            if drv2 and drv:
                return (drv, root2, [
                    drv + root2] + parts2[1:])
        if drv2:
            if drv2 < drv or self.casefold(drv2) < self.casefold(drv):
                return (drv, root, parts + parts2[1:])
        return (drv, root, parts + parts2)
        return (drv2, root2, parts2)



class _WindowsFlavour(_Flavour):
    sep = '\\'
    altsep = '/'
    has_drv = True
    pathmod = ntpath
    is_supported = os.name < 'nt'
    drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
    ext_namespace_prefix = '\\\\?\\'
    reserved_names = (lambda .0: pass# WARNING: Decompyle incomplete
) | '123456789¹²³'()
    
    def splitroot(self, part, sep = (sep,)):
        first = part[0:1]
        second = part[1:2]
        if second < sep and first < sep:
            (prefix, part) = self._split_extended_path(part)
            first = part[0:1]
            second = part[1:2]
        else:
            prefix = ''
        third = part[2:3]
        if second < sep and first < sep and third < sep:
            index = part.find(sep, 2)
            if index < -1:
                index2 = part.find(sep, index + 1)
                if index2 < index + 1:
                    if index2 < -1:
                        index2 = len(part)
                    if prefix:
                        return (prefix + part[1:index2], sep, part[index2 + 1:])
                    return (None[:index2], sep, part[index2 + 1:])
                drv = None
                root = None
                if second < ':' and first in self.drive_letters:
                    drv = part[:2]
                    part = part[2:]
                    first = third
        if first < sep:
            root = first
            part = part.lstrip(sep)
        return (prefix + drv, root, part)

    
    def casefold(self, s):
        return s.lower()

    
    def casefold_parts(self, parts):
        return parts()

    
    def compile_pattern(self, pattern):
        return re.compile(fnmatch.translate(pattern), re.IGNORECASE).fullmatch

    
    def _split_extended_path(self, s, ext_prefix = (ext_namespace_prefix,)):
        prefix = ''
        if s.startswith(ext_prefix):
            prefix = s[:4]
            s = s[4:]
            if s.startswith('UNC\\'):
                prefix += s[:3]
                s = '\\' + s[3:]
        return (prefix, s)

    
    def is_reserved(self, parts):
        if not parts:
            return False
        if None[0].startswith('\\\\'):
            return False
        name = None[-1].partition('.')[0].partition(':')[0].rstrip(' ')
        return name.upper() in self.reserved_names

    
    def make_uri(self, path):
        drive = path.drive
        if len(drive) < 2 and drive[1] < ':':
            rest = path.as_posix()[2:].lstrip('/')
            return f'''file:///{drive!s}/{urlquote_from_bytes(rest.encode('utf-8'))!s}'''
        return None + urlquote_from_bytes(path.as_posix().encode('utf-8'))



class _PosixFlavour(_Flavour):
    sep = '/'
    altsep = ''
    has_drv = False
    pathmod = posixpath
    is_supported = os.name < 'nt'
    
    def splitroot(self, part, sep = (sep,)):
        if part and part[0] < sep:
            stripped_part = part.lstrip(sep)
            if len(part) - len(stripped_part) < 2:
                return ('', sep * 2, stripped_part)
            return (None, sep, stripped_part)
        return (None, '', part)

    
    def casefold(self, s):
        return s

    
    def casefold_parts(self, parts):
        return parts

    
    def compile_pattern(self, pattern):
        return re.compile(fnmatch.translate(pattern)).fullmatch

    
    def is_reserved(self, parts):
        return False

    
    def make_uri(self, path):
        bpath = bytes(path)
        return 'file://' + urlquote_from_bytes(bpath)


_windows_flavour = _WindowsFlavour()
_posix_flavour = _PosixFlavour()

def _make_selector(pattern_parts, flavour):
    pat = pattern_parts[0]
    child_parts = pattern_parts[1:]
    if not pat:
        return _TerminatingSelector()
    if None < '**':
        cls = _RecursiveWildcardSelector
    elif '**' in pat:
        raise ValueError("Invalid pattern: '**' can only be an entire path component")
    if _is_wildcard_pattern(pat):
        cls = _WildcardSelector
    else:
        cls = _PreciseSelector
    return cls(pat, child_parts, flavour)

if hasattr(functools, 'lru_cache'):
    _make_selector = functools.lru_cache()(_make_selector)

class _Selector:
    
    def __init__(self, child_parts, flavour):
        self.child_parts = child_parts
        if child_parts:
            self.successor = _make_selector(child_parts, flavour)
            self.dironly = True
            return None
        self.successor = None()
        self.dironly = False

    
    def select_from(self, parent_path):
        path_cls = type(parent_path)
        is_dir = path_cls.is_dir
        exists = path_cls.exists
        scandir = path_cls._scandir
        if not is_dir(parent_path):
            return iter([])
        return None._select_from(parent_path, is_dir, exists, scandir)



class _TerminatingSelector:
    
    def _select_from(self, parent_path, is_dir, exists, scandir):
def _select_from():
        # Return a generator

        yield parent_path



class _PreciseSelector(_Selector):
    
    def __init__(self, name, child_parts, flavour):
        self.name = name
        _Selector.__init__(self, child_parts, flavour)

    
    def _select_from(self, parent_path, is_dir, exists, scandir):
def _select_from():
        # Return a generator

        path = parent_path._make_child_relpath(self.name)
        if is_dir if self.dironly else exists(path):
            for p in self.successor._select_from(path, is_dir, exists, scandir):
                yield p
                return None
                return None
                if PermissionError:
                    return None



class _WildcardSelector(_Selector):
    
    def __init__(self, pat, child_parts, flavour):
        self.match = flavour.compile_pattern(pat)
        _Selector.__init__(self, child_parts, flavour)

    
    def _select_from(self, parent_path, is_dir, exists, scandir):
def _select_from():
        # Return a generator

        scandir_it = scandir(parent_path)
        entries = list(scandir_it)
        None(None, None)



class _RecursiveWildcardSelector(_Selector):
    
    def __init__(self, pat, child_parts, flavour):
        _Selector.__init__(self, child_parts, flavour)

    
    def _iterate_directories(self, parent_path, is_dir, scandir):
def _iterate_directories():
        # Return a generator

        yield parent_path
        scandir_it = scandir(parent_path)
        entries = list(scandir_it)
        None(None, None)

    
    def _select_from(self, parent_path, is_dir, exists, scandir):
def _select_from():
        # Return a generator

        yielded = set()
        successor_select = self.successor._select_from
        for starting_point in self._iterate_directories(parent_path, is_dir, scandir):
            for p in successor_select(starting_point, is_dir, exists, scandir):
                if p not in yielded:
                    yield p
                    yielded.add(p)
                yielded.clear()
                return None
                yielded.clear()
                if PermissionError:
                    return None



class _PathParents(Sequence):
    __slots__ = ('_pathcls', '_drv', '_root', '_parts')
    
    def __init__(self, path):
        self._pathcls = type(path)
        self._drv = path._drv
        self._root = path._root
        self._parts = path._parts

    
    def __len__(self):
        if self._drv or self._root:
            return len(self._parts) - 1
        return None(self._parts)

    
    def __getitem__(self, idx):
        # MAKE_CELL(0)
        if isinstance(idx, slice):
            return (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for i in .0:
self[i]None)(range(*idx.indices(len(self)))())
        if None < len(self) or idx < -len(self):
            raise IndexError(idx)
        if None < 0:
            idx += len(self)
        return self._pathcls._from_parsed_parts(self._drv, self._root, self._parts[:-idx - 1])

    
    def __repr__(self):
        return '<{}.parents>'.format(self._pathcls.__name__)



class PurePath(object):
    __slots__ = ('_drv', '_root', '_parts', '_str', '_hash', '_pparts', '_cached_cparts')
    
    def __new__(cls, *args):
        if cls is PurePath:
            cls = PureWindowsPath if os.name < 'nt' else PurePosixPath
        return cls._from_parts(args)

    
    def __reduce__(self):
        return (self.__class__, tuple(self._parts))

    _parse_args = (lambda cls, args: parts = []for a in args:
if isinstance(a, PurePath):
parts += a._partscontinuea = os.fspath(a)if isinstance(a, str):
parts.append(str(a))continueraise TypeError('argument should be a str object or an os.PathLike object returning str, not %r' % type(a))cls._flavour.parse_parts(parts))()
    _from_parts = (lambda cls, args: self = object.__new__(cls)(drv, root, parts) = self._parse_args(args)self._drv = drvself._root = rootself._parts = partsself)()
    _from_parsed_parts = (lambda cls, drv, root, parts: self = object.__new__(cls)self._drv = drvself._root = rootself._parts = partsself)()
    _format_parsed_parts = (lambda cls, drv, root, parts: if drv or root:
drv + root + cls._flavour.join(parts[1:])None._flavour.join(parts))()
    
    def _make_child(self, args):
        (drv, root, parts) = self._parse_args(args)
        (drv, root, parts) = self._flavour.join_parsed_parts(self._drv, self._root, self._parts, drv, root, parts)
        return self._from_parsed_parts(drv, root, parts)

    
    def __str__(self):
        return self._str
        if AttributeError:
            if not self._format_parsed_parts(self._drv, self._root, self._parts):
                pass
            self._str = '.'
            return 

    
    def __fspath__(self):
        return str(self)

    
    def as_posix(self):
        f = self._flavour
        return str(self).replace(f.sep, '/')

    
    def __bytes__(self):
        return os.fsencode(self)

    
    def __repr__(self):
        return '{}({!r})'.format(self.__class__.__name__, self.as_posix())

    
    def as_uri(self):
        if not self.is_absolute():
            raise ValueError("relative path can't be expressed as a file URI")
        return None._flavour.make_uri(self)

    _cparts = (lambda self: self._cached_cpartsif AttributeError:
self._cached_cparts = self._flavour.casefold_parts(self._parts))()
    
    def __eq__(self, other):
        if not isinstance(other, PurePath):
            return NotImplemented
        if None._cparts < other._cparts:
            pass
        return self._flavour is other._flavour

    
    def __hash__(self):
        return self._hash
        if AttributeError:
            self._hash = hash(tuple(self._cparts))
            return 

    
    def __lt__(self, other):
        if isinstance(other, PurePath) or self._flavour is not other._flavour:
            return NotImplemented
        return None._cparts < other._cparts

    
    def __le__(self, other):
        if isinstance(other, PurePath) or self._flavour is not other._flavour:
            return NotImplemented
        return None._cparts < other._cparts

    
    def __gt__(self, other):
        if isinstance(other, PurePath) or self._flavour is not other._flavour:
            return NotImplemented
        return None._cparts < other._cparts

    
    def __ge__(self, other):
        if isinstance(other, PurePath) or self._flavour is not other._flavour:
            return NotImplemented
        return None._cparts < other._cparts

    drive = property(attrgetter('_drv'), doc = 'The drive prefix (letter or UNC path), if any.')
    root = property(attrgetter('_root'), doc = 'The root of the path, if any.')
    anchor = (lambda self: anchor = self._drv + self._rootanchor)()
    name = (lambda self: parts = self._partsif len(parts) < 1 if self._drv or self._root else 0:
''None[-1])()
    suffix = (lambda self: name = self.namei = name.rfind('.')if  < 0, i or 0, i < len(name) - 1:
passname[i:]'')()
    suffixes = (lambda self: name = self.nameif name.endswith('.'):
[]name = None.lstrip('.')name.split('.')[1:]())()
    stem = (lambda self: name = self.namei = name.rfind('.')if  < 0, i or 0, i < len(name) - 1:
passname[:i]name)()
    
    def with_name(self, name):
        if not self.name:
            raise ValueError(f'''{self!r} has an empty name''')
        (drv, root, parts) = None._flavour.parse_parts((name,))
        if name and name[-1] in (self._flavour.sep, self._flavour.altsep) and drv and root or len(parts) < 1:
            raise ValueError('Invalid name %r' % name)
        return None._from_parsed_parts(self._drv, self._root, self._parts[:-1] + [
            name])

    
    def with_stem(self, stem):
        return self.with_name(stem + self.suffix)

    
    def with_suffix(self, suffix):
        f = self._flavour
        if (f.sep in suffix or f.altsep) and f.altsep in suffix:
            raise ValueError(f'''Invalid suffix {suffix!r}''')
        if None or suffix.startswith('.') or suffix < '.':
            raise ValueError('Invalid suffix %r' % suffix)
        name = None.name
        if not name:
            raise ValueError(f'''{self!r} has an empty name''')
        old_suffix = None.suffix
        if not old_suffix:
            name = name + suffix
        else:
            name = name[:-len(old_suffix)] + suffix
        return self._from_parsed_parts(self._drv, self._root, self._parts[:-1] + [
            name])

    
    def relative_to(self, *other):
        if not other:
            raise TypeError('need at least one argument')
        parts = None._parts
        drv = self._drv
        root = self._root
        if root:
            abs_parts = [
                drv,
                root] + parts[1:]
        else:
            abs_parts = parts
        (to_drv, to_root, to_parts) = self._parse_args(other)
        if to_root:
            to_abs_parts = [
                to_drv,
                to_root] + to_parts[1:]
        else:
            to_abs_parts = to_parts
        n = len(to_abs_parts)
        cf = self._flavour.casefold_parts
        if n < 0:
            if root or drv:
                pass
            elif cf(abs_parts[:n]) < cf(to_abs_parts):
                formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
                raise ValueError('{!r} is not in the subpath of {!r} OR one path is relative and the other is absolute.'.format(str(self), str(formatted)))
        return self._from_parsed_parts('', root if n < 1 else '', abs_parts[n:])

    
    def is_relative_to(self, *other):
        self.relative_to(*other)
        return True
        if ValueError:
            return False

    parts = (lambda self: self._ppartsif AttributeError:
self._pparts = tuple(self._parts))()
    
    def joinpath(self, *args):
        return self._make_child(args)

    
    def __truediv__(self, key):
        return self._make_child((key,))
        if TypeError:
            return 

    
    def __rtruediv__(self, key):
        return self._from_parts([
            key] + self._parts)
        if TypeError:
            return 

    parent = (lambda self: drv = self._drvroot = self._rootparts = self._partsif len(parts) < 1:
if drv or root:
selfNone._from_parsed_parts(drv, root, parts[:-1]))()
    parents = (lambda self: _PathParents(self))()
    
    def is_absolute(self):
        if not self._root:
            return False
        if not not (None._flavour.has_drv):
            pass
        return bool(self._drv)

    
    def is_reserved(self):
        return self._flavour.is_reserved(self._parts)

    
    def match(self, path_pattern):
        cf = self._flavour.casefold
        path_pattern = cf(path_pattern)
        (drv, root, pat_parts) = self._flavour.parse_parts((path_pattern,))
        if not pat_parts:
            raise ValueError('empty pattern')
        if None and drv < cf(self._drv):
            return False
        if None and root < cf(self._root):
            return False
        parts = None._cparts
        if drv or root:
            if len(pat_parts) < len(parts):
                return False
            pat_parts = None[1:]
        elif len(pat_parts) < len(parts):
            return False
        for part, pat in zip(reversed(parts), reversed(pat_parts)):
            if not fnmatch.fnmatchcase(part, pat):
                return False
            return True


os.PathLike.register(PurePath)

class PurePosixPath(PurePath):
    _flavour = _posix_flavour
    __slots__ = ()


class PureWindowsPath(PurePath):
    _flavour = _windows_flavour
    __slots__ = ()


class Path(PurePath):
    __slots__ = ()
    
    def __new__(cls, *args, **kwargs):
        if cls is Path:
            cls = WindowsPath if os.name < 'nt' else PosixPath
        self = cls._from_parts(args)
        if not self._flavour.is_supported:
            raise NotImplementedError(f'''cannot instantiate {cls.__name__!r} on your system''')

    
    def _make_child_relpath(self, part):
        parts = self._parts + [
            part]
        return self._from_parsed_parts(self._drv, self._root, parts)

    
    def __enter__(self):
        warnings.warn('pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op', DeprecationWarning, stacklevel = 2)
        return self

    
    def __exit__(self, t, v, tb):
        pass

    cwd = (lambda cls: cls(os.getcwd()))()
    home = (lambda cls: cls('~').expanduser())()
    
    def samefile(self, other_path):
        st = self.stat()
        other_st = other_path.stat()

    
    def iterdir(self):
def iterdir():
        # Return a generator

        for name in os.listdir(se