1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
from __future__ import annotations
import enum
import sys
from collections.abc import Callable
from os import PathLike
from typing import TYPE_CHECKING
from typing import Any
from typing import Optional
from typing import Protocol
from typing import Union
from typing import runtime_checkable
from upath.types._abc import JoinablePath
from upath.types._abc import PathInfo
from upath.types._abc import PathParser
from upath.types._abc import ReadablePath
from upath.types._abc import WritablePath
if TYPE_CHECKING:
if sys.version_info >= (3, 12):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
__all__ = [
"JoinablePath",
"ReadablePath",
"WritablePath",
"JoinablePathLike",
"ReadablePathLike",
"WritablePathLike",
"SupportsPathLike",
"PathInfo",
"StatResultType",
"PathParser",
"UPathParser",
"UNSET_DEFAULT",
"OnNameCollisionFunc",
]
class VFSPathLike(Protocol):
def __vfspath__(self) -> str: ...
SupportsPathLike: TypeAlias = Union[VFSPathLike, PathLike[str]]
JoinablePathLike: TypeAlias = Union[JoinablePath, SupportsPathLike, str]
ReadablePathLike: TypeAlias = Union[ReadablePath, SupportsPathLike, str]
WritablePathLike: TypeAlias = Union[WritablePath, SupportsPathLike, str]
class _DefaultValue(enum.Enum):
UNSET = enum.auto()
UNSET_DEFAULT: Any = _DefaultValue.UNSET
# We can't assume this, because pathlib_abc==0.5.1 is ahead of stdlib 3.14
# if sys.version_info >= (3, 14):
# JoinablePath.register(pathlib.PurePath)
# ReadablePath.register(pathlib.Path)
# WritablePath.register(pathlib.Path)
@runtime_checkable
class StatResultType(Protocol):
"""duck-type for os.stat_result"""
@property
def st_mode(self) -> int: ...
@property
def st_ino(self) -> int: ...
@property
def st_dev(self) -> int: ...
@property
def st_nlink(self) -> int: ...
@property
def st_uid(self) -> int: ...
@property
def st_gid(self) -> int: ...
@property
def st_size(self) -> int: ...
@property
def st_atime(self) -> float: ...
@property
def st_mtime(self) -> float: ...
@property
def st_ctime(self) -> float: ...
@property
def st_atime_ns(self) -> int: ...
@property
def st_mtime_ns(self) -> int: ...
@property
def st_ctime_ns(self) -> int: ...
# st_birthtime is available on Windows (3.12+), FreeBSD, and macOS
# On Linux it's currently unavailable
# see: https://discuss.python.org/t/st-birthtime-not-available/104350/2
if (sys.platform == "win32" and sys.version_info >= (3, 12)) or (
sys.platform == "darwin" or sys.platform.startswith("freebsd")
):
@property
def st_birthtime(self) -> float: ...
@runtime_checkable
class UPathParser(PathParser, Protocol):
"""duck-type for upath.core.UPathParser"""
def split(self, path: JoinablePathLike) -> tuple[str, str]: ...
def splitext(self, path: JoinablePathLike) -> tuple[str, str]: ...
def normcase(self, path: JoinablePathLike) -> str: ...
def strip_protocol(self, path: JoinablePathLike) -> str: ...
def join(
self,
path: JoinablePathLike,
*paths: JoinablePathLike,
) -> str: ...
def isabs(self, path: JoinablePathLike) -> bool: ...
def splitdrive(self, path: JoinablePathLike) -> tuple[str, str]: ...
def splitroot(self, path: JoinablePathLike) -> tuple[str, str, str]: ...
OnNameCollisionFunc: TypeAlias = Callable[
[ReadablePath, WritablePath], tuple[Optional[WritablePath], Optional[WritablePath]]
]
|