codekingpro/portable-devtools
114k
1import sys2from asyncio import AbstractEventLoop3from datetime import datetime, time, timedelta4from logging import Handler5from multiprocessing.context import BaseContext6from types import TracebackType7from typing import (8 Any,9 BinaryIO,10 Callable,11 Dict,12 Generator,13 Generic,14 List,15 NamedTuple,16 NewType,17 Optional,18 Pattern,19 Sequence,20 TextIO,21 Tuple,22 Type,23 TypeVar,24 Union,25 overload,26)27 28if sys.version_info >= (3, 6):29 from typing import Awaitable30else:31 from typing_extensions import Awaitable32 33if sys.version_info >= (3, 6):34 from os import PathLike35 from typing import ContextManager36 37 PathLikeStr = PathLike[str]38else:39 from pathlib import PurePath as PathLikeStr40 41 from typing_extensions import ContextManager42 43if sys.version_info >= (3, 8):44 from typing import Protocol, TypedDict45else:46 from typing_extensions import Protocol, TypedDict47 48_T = TypeVar("_T")49_F = TypeVar("_F", bound=Callable[..., Any])50ExcInfo = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]51 52class _GeneratorContextManager(ContextManager[_T], Generic[_T]):53 def __call__(self, func: _F) -> _F: ...54 def __exit__(55 self,56 typ: Optional[Type[BaseException]],57 value: Optional[BaseException],58 traceback: Optional[TracebackType],59 ) -> Optional[bool]: ...60 61Catcher = NewType("Catcher", _GeneratorContextManager[None])62Contextualizer = NewType("Contextualizer", _GeneratorContextManager[None])63AwaitableCompleter = Awaitable[None]64 65class Level(NamedTuple):66 name: str67 no: int68 color: str69 icon: str70 71class _RecordAttribute:72 def __format__(self, spec: str) -> str: ...73 74class RecordFile(_RecordAttribute):75 name: str76 path: str77 78class RecordLevel(_RecordAttribute):79 name: str80 no: int81 icon: str82 83class RecordThread(_RecordAttribute):84 id: int85 name: str86 87class RecordProcess(_RecordAttribute):88 id: int89 name: str90 91class RecordException(NamedTuple):92 type: Optional[Type[BaseException]]93 value: Optional[BaseException]94 traceback: Optional[TracebackType]95 96class Record(TypedDict):97 elapsed: timedelta98 exception: Optional[RecordException]99 extra: Dict[Any, Any]100 file: RecordFile101 function: str102 level: RecordLevel103 line: int104 message: str105 module: str106 name: Optional[str]107 process: RecordProcess108 thread: RecordThread109 time: datetime110 111class Message(str):112 record: Record113 114class Writable(Protocol):115 def write(self, message: Message) -> None: ...116 117FilterDict = Dict[Optional[str], Union[str, int, bool]]118FilterFunction = Callable[[Record], bool]119FormatFunction = Callable[[Record], str]120PatcherFunction = Callable[[Record], None]121RotationFunction = Callable[[Message, TextIO], bool]122RetentionFunction = Callable[[List[str]], None]123CompressionFunction = Callable[[str], None]124 125StandardOpener = Callable[[str, int], int]126 127class BasicHandlerConfig(TypedDict, total=False):128 sink: Union[TextIO, Writable, Callable[[Message], None], Handler]129 level: Union[str, int]130 format: Union[str, FormatFunction]131 filter: Optional[Union[str, FilterFunction, FilterDict]]132 colorize: Optional[bool]133 serialize: bool134 backtrace: bool135 diagnose: bool136 enqueue: bool137 catch: bool138 139class FileHandlerConfig(TypedDict, total=False):140 sink: Union[str, PathLikeStr]141 level: Union[str, int]142 format: Union[str, FormatFunction]143 filter: Optional[Union[str, FilterFunction, FilterDict]]144 colorize: Optional[bool]145 serialize: bool146 backtrace: bool147 diagnose: bool148 enqueue: bool149 catch: bool150 rotation: Optional[Union[str, int, time, timedelta, RotationFunction]]151 retention: Optional[Union[str, int, timedelta, RetentionFunction]]152 compression: Optional[Union[str, CompressionFunction]]153 delay: bool154 watch: bool155 mode: str156 buffering: int157 encoding: str158 errors: Optional[str]159 newline: Optional[str]160 closefd: bool161 opener: Optional[StandardOpener]162 163class AsyncHandlerConfig(TypedDict, total=False):164 sink: Callable[[Message], Awaitable[None]]165 level: Union[str, int]166 format: Union[str, FormatFunction]167 filter: Optional[Union[str, FilterFunction, FilterDict]]168 colorize: Optional[bool]169 serialize: bool170 backtrace: bool171 diagnose: bool172 enqueue: bool173 catch: bool174 context: Optional[Union[str, BaseContext]]175 loop: Optional[AbstractEventLoop]176 177HandlerConfig = Union[BasicHandlerConfig, FileHandlerConfig, AsyncHandlerConfig]178 179class LevelConfig(TypedDict, total=False):180 name: str181 no: int182 color: str183 icon: str184 185ActivationConfig = Tuple[Optional[str], bool]186 187class Logger:188 @overload189 def add(190 self,191 sink: Union[TextIO, Writable, Callable[[Message], None], Handler],192 *,193 level: Union[str, int] = ...,194 format: Union[str, FormatFunction] = ...,195 filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,196 colorize: Optional[bool] = ...,197 serialize: bool = ...,198 backtrace: bool = ...,199 diagnose: bool = ...,200 enqueue: bool = ...,201 context: Optional[Union[str, BaseContext]] = ...,202 catch: bool = ...203 ) -> int: ...204 @overload205 def add(206 self,207 sink: Callable[[Message], Awaitable[None]],208 *,209 level: Union[str, int] = ...,210 format: Union[str, FormatFunction] = ...,211 filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,212 colorize: Optional[bool] = ...,213 serialize: bool = ...,214 backtrace: bool = ...,215 diagnose: bool = ...,216 enqueue: bool = ...,217 catch: bool = ...,218 context: Optional[Union[str, BaseContext]] = ...,219 loop: Optional[AbstractEventLoop] = ...220 ) -> int: ...221 @overload222 def add(223 self,224 sink: Union[str, PathLikeStr],225 *,226 level: Union[str, int] = ...,227 format: Union[str, FormatFunction] = ...,228 filter: Optional[Union[str, FilterFunction, FilterDict]] = ...,229 colorize: Optional[bool] = ...,230 serialize: bool = ...,231 backtrace: bool = ...,232 diagnose: bool = ...,233 enqueue: bool = ...,234 context: Optional[Union[str, BaseContext]] = ...,235 catch: bool = ...,236 rotation: Optional[Union[str, int, time, timedelta, RotationFunction]] = ...,237 retention: Optional[Union[str, int, timedelta, RetentionFunction]] = ...,238 compression: Optional[Union[str, CompressionFunction]] = ...,239 delay: bool = ...,240 watch: bool = ...,241 mode: str = ...,242 buffering: int = ...,243 encoding: str = ...,244 errors: Optional[str] = ...,245 newline: Optional[str] = ...,246 closefd: bool = ...,247 opener: Optional[StandardOpener] = ...,248 ) -> int: ...249 def remove(self, handler_id: Optional[int] = ...) -> None: ...250 def complete(self) -> AwaitableCompleter: ...251 @overload252 def catch(253 self,254 exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]] = ...,255 *,256 level: Union[str, int] = ...,257 reraise: bool = ...,258 onerror: Optional[Callable[[BaseException], None]] = ...,259 exclude: Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]] = ...,260 default: Any = ...,261 message: str = ...262 ) -> Catcher: ...263 @overload264 def catch(self, function: _F) -> _F: ...265 def opt(266 self,267 *,268 exception: Optional[Union[bool, ExcInfo, BaseException]] = ...,269 record: bool = ...,270 lazy: bool = ...,271 colors: bool = ...,272 raw: bool = ...,273 capture: bool = ...,274 depth: int = ...,275 ansi: bool = ...276 ) -> Logger: ...277 def bind(__self, **kwargs: Any) -> Logger: ... # noqa: N805278 def contextualize(__self, **kwargs: Any) -> Contextualizer: ... # noqa: N805279 def patch(self, patcher: PatcherFunction) -> Logger: ...280 @overload281 def level(self, name: str) -> Level: ...282 @overload283 def level(284 self, name: str, no: int = ..., color: Optional[str] = ..., icon: Optional[str] = ...285 ) -> Level: ...286 @overload287 def level(288 self,289 name: str,290 no: Optional[int] = ...,291 color: Optional[str] = ...,292 icon: Optional[str] = ...,293 ) -> Level: ...294 def disable(self, name: Optional[str]) -> None: ...295 def enable(self, name: Optional[str]) -> None: ...296 def configure(297 self,298 *,299 handlers: Optional[Sequence[HandlerConfig]] = ...,300 levels: Optional[Sequence[LevelConfig]] = ...,301 extra: Optional[Dict[Any, Any]] = ...,302 patcher: Optional[PatcherFunction] = ...,303 activation: Optional[Sequence[ActivationConfig]] = ...304 ) -> List[int]: ...305 # @staticmethod cannot be used with @overload in mypy (python/mypy#7781).306 # However Logger is not exposed and logger is an instance of Logger307 # so for type checkers it is all the same whether it is defined here308 # as a static method or an instance method.309 @overload310 def parse(311 self,312 file: Union[str, PathLikeStr, TextIO],313 pattern: Union[str, Pattern[str]],314 *,315 cast: Union[Dict[str, Callable[[str], Any]], Callable[[Dict[str, str]], None]] = ...,316 chunk: int = ...317 ) -> Generator[Dict[str, Any], None, None]: ...318 @overload319 def parse(320 self,321 file: BinaryIO,322 pattern: Union[bytes, Pattern[bytes]],323 *,324 cast: Union[Dict[str, Callable[[bytes], Any]], Callable[[Dict[str, bytes]], None]] = ...,325 chunk: int = ...326 ) -> Generator[Dict[str, Any], None, None]: ...327 @overload328 def trace(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805329 @overload330 def trace(__self, __message: Any) -> None: ... # noqa: N805331 @overload332 def debug(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805333 @overload334 def debug(__self, __message: Any) -> None: ... # noqa: N805335 @overload336 def info(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805337 @overload338 def info(__self, __message: Any) -> None: ... # noqa: N805339 @overload340 def success(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805341 @overload342 def success(__self, __message: Any) -> None: ... # noqa: N805343 @overload344 def warning(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805345 @overload346 def warning(__self, __message: Any) -> None: ... # noqa: N805347 @overload348 def error(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805349 @overload350 def error(__self, __message: Any) -> None: ... # noqa: N805351 @overload352 def critical(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805353 @overload354 def critical(__self, __message: Any) -> None: ... # noqa: N805355 @overload356 def exception(__self, __message: str, *args: Any, **kwargs: Any) -> None: ... # noqa: N805357 @overload358 def exception(__self, __message: Any) -> None: ... # noqa: N805359 @overload360 def log(361 __self, __level: Union[int, str], __message: str, *args: Any, **kwargs: Any # noqa: N805362 ) -> None: ...363 @overload364 def log(__self, __level: Union[int, str], __message: Any) -> None: ... # noqa: N805365 def start(self, *args: Any, **kwargs: Any) -> int: ...366 def stop(self, *args: Any, **kwargs: Any) -> None: ...367 368logger: Logger369 