|
17 | 17 | import fnmatch |
18 | 18 | import re |
19 | 19 |
|
20 | | -from typing import Any, Callable, Dict, List, Optional, Tuple, Union |
21 | | -# from typing import TypedDict |
| 20 | +from typing import Any, Callable, Dict, List, Optional, Tuple, Union, TYPE_CHECKING |
| 21 | + |
| 22 | +import sys |
| 23 | + |
| 24 | +if sys.version_info >= (3, 8): |
| 25 | + from typing import TypedDict # pylint: disable=no-name-in-module |
| 26 | +else: |
| 27 | + from typing_extensions import TypedDict |
| 28 | + |
| 29 | + |
| 30 | +if TYPE_CHECKING: |
| 31 | + from playwright_web.network import Route, Request |
22 | 32 |
|
23 | 33 | Cookie = List[Dict[str, Union[str, int, bool]]] |
24 | 34 | URLMatch = Union[str, Callable[[str], bool]] |
25 | | -FilePayload = Dict # TypedDict('FilePayload', name=str, mimeType=str, buffer=bytes) |
26 | | -FrameMatch = Dict # TypedDict('FrameMatch', url=URLMatch, name=str) |
27 | | -PendingWaitEvent = Dict # TypedDict('PendingWaitEvent', event=str, future=asyncio.Future) |
28 | 35 | RouteHandler = Callable[['Route', 'Request'], None] |
29 | | -RouteHandlerEntry = Dict # TypedDict('RouteHandlerEntry', matcher=URLMatcher, handler=RouteHandler) |
30 | | -SelectOption = Dict # TypedDict('SelectOption', value=Optional[str], label=Optional[str], index=Optional[str]) |
31 | | -ConsoleMessageLocation = Dict #TypedDict('ConsoleMessageLocation', url=Optional[str], lineNumber=Optional[int], columnNumber=Optional[int]) |
32 | 36 | FunctionWithSource = Callable[[Dict], Any] |
33 | | -ErrorPayload = Dict # TypedDict('ErrorPayload', message=str, name=str, stack=str, value=Any) |
| 37 | +class FilePayload(TypedDict): |
| 38 | + name: str |
| 39 | + mimeType: str |
| 40 | + buffer: bytes |
| 41 | +class FrameMatch(TypedDict): |
| 42 | + url: URLMatch |
| 43 | + name: str |
| 44 | +class PendingWaitEvent(TypedDict): |
| 45 | + event: str |
| 46 | + future: asyncio.Future |
| 47 | + |
| 48 | +class RouteHandlerEntry(TypedDict): |
| 49 | + matcher: "URLMatcher" |
| 50 | + handler: RouteHandler |
| 51 | +class SelectOption(TypedDict): |
| 52 | + value: Optional[str] |
| 53 | + label: Optional[str] |
| 54 | + index: Optional[str] |
| 55 | +class ConsoleMessageLocation(TypedDict): |
| 56 | + url: Optional[str] |
| 57 | + lineNumber: Optional[int] |
| 58 | + columnNumber: Optional[int] |
| 59 | +class ErrorPayload(TypedDict): |
| 60 | + message: str |
| 61 | + name: str |
| 62 | + stack: str |
| 63 | + value: Any |
34 | 64 |
|
35 | 65 | class URLMatcher: |
36 | 66 | def __init__(self, match: URLMatch): |
|
0 commit comments