GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — playwright-python/scripts/generate_api.py at master · PragmaticCoder/playwright-python Expand file tree/ Copy pathgenerate_api.pyMore file actions 256 lines (226 loc) · 8.67 KB / Copy pathgenerate_api.pyFile metadata and controls256 lines (226 loc) · 8.67 KB 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 # Copyright (c) Microsoft Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import re from types import FunctionType from typing import ( # type: ignore Any, List, Match, Union, cast, get_args, get_origin, get_type_hints, ) from playwright._impl._accessibility import Accessibility from playwright._impl._browser import Browser from playwright._impl._browser_context import BrowserContext from playwright._impl._browser_type import BrowserType from playwright._impl._cdp_session import CDPSession from playwright._impl._chromium_browser_context import ChromiumBrowserContext from playwright._impl._console_message import ConsoleMessage from playwright._impl._dialog import Dialog from playwright._impl._download import Download from playwright._impl._element_handle import ElementHandle from playwright._impl._file_chooser import FileChooser from playwright._impl._frame import Frame from playwright._impl._helper import to_snake_case from playwright._impl._input import Keyboard, Mouse, Touchscreen from playwright._impl._js_handle import JSHandle, Serializable from playwright._impl._network import Request, Response, Route, WebSocket from playwright._impl._page import Page, Worker from playwright._impl._playwright import Playwright from playwright._impl._selectors import Selectors from playwright._impl._video import Video def process_type(value: Any, param: bool = False) -> str: value = str(value) value = re.sub(r"<class '([^']+)'>", r"\1", value) value = re.sub(r"playwright\._impl\._api_structures.([\w]+)", r"\1", value) value = re.sub(r"playwright\._impl\.[\w]+\.([\w]+)", r'"\1"', value) value = re.sub(r"typing.Literal", "Literal", value) if param: value = re.sub(r"^typing.Union\[([^,]+), NoneType\]$", r"\1 = None", value) value = re.sub( r"typing.Union\[(Literal\[[^\]]+\]), NoneType\]", r"\1 = None", value ) value = re.sub( r"^typing.Union\[(.+), NoneType\]$", r"typing.Union[\1] = None", value ) return value positional_exceptions = [ r"abort\.errorCode", r"accept\.promptText", r"add_init_script\.script", r"cookies\.urls", r"dispatch_event\.eventInit", r"eval.*\.arg", r"expect_.*\.predicate", r"evaluate_handle\.arg", r"frame.*\.name", r"register\.script", r"select_option\.value", r"send\.params", r"set_geolocation\.geolocation", r"wait_for_.*\.predicate", r"wait_for_load_state\.state", r"unroute\.handler", ] def is_positional_exception(key: str) -> bool: for pattern in positional_exceptions: if re.match(pattern, key): return True return False def signature(func: FunctionType, indent: int) -> str: hints = get_type_hints(func, globals()) tokens = ["self"] split = ",\n" + " " * indent saw_optional = False for [name, value] in hints.items(): if name == "return": continue positional_exception = is_positional_exception(f"{func.__name__}.{name}") if saw_optional and positional_exception: raise Exception( "Positional exception is not first in the list " + f"{func.__name__}.{name}" ) if ( not positional_exception and not saw_optional and str(value).endswith("NoneType]") ): saw_optional = True tokens.append("*") processed = process_type(value, True) tokens.append(f"{to_snake_case(name)}: {processed}") return split.join(tokens) def arguments(func: FunctionType, indent: int) -> str: hints = get_type_hints(func, globals()) tokens = [] split = ",\n" + " " * indent for [name, value] in hints.items(): value_str = str(value) if name == "return": continue if "Callable" in value_str: tokens.append(f"{name}=self._wrap_handler({to_snake_case(name)})") elif ( "typing.Any" in value_str or "typing.Dict" in value_str or "Handle" in value_str ): tokens.append(f"{name}=mapping.to_impl({to_snake_case(name)})") elif ( re.match(r"<class 'playwright\._impl\.[\w]+\.[\w]+", value_str) and "_api_structures" not in value_str ): tokens.append(f"{name}={to_snake_case(name)}._impl_obj") else: tokens.append(f"{name}={to_snake_case(name)}") return split.join(tokens) def return_type(func: FunctionType) -> str: value = get_type_hints(func, globals())["return"] return process_type(value) def short_name(t: Any) -> str: match = cast( Match[str], re.compile(r"playwright\._impl\.[^.]+\.([^']+)").search(str(t)) ) return match.group(1) def return_value(value: Any) -> List[str]: value_str = str(value) if "playwright" not in value_str: return ["mapping.from_maybe_impl(", ")"] if ( get_origin(value) == Union and len(get_args(value)) == 2 and str(get_args(value)[1]) == "<class 'NoneType'>" ): return ["mapping.from_impl_nullable(", ")"] if str(get_origin(value)) == "<class 'list'>": return ["mapping.from_impl_list(", ")"] if str(get_origin(value)) == "<class 'dict'>": return ["mapping.from_impl_dict(", ")"] return ["mapping.from_impl(", ")"] header = """ # Copyright (c) Microsoft Corporation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import typing import sys import pathlib if sys.version_info >= (3, 8): # pragma: no cover from typing import Literal else: # pragma: no cover from typing_extensions import Literal from playwright._impl._accessibility import Accessibility as AccessibilityImpl from playwright._impl._api_structures import Cookie, FloatRect, FilePayload, Geolocation, HttpCredentials, PdfMargins, Position, ProxySettings, ResourceTiming, SourceLocation, StorageState, ViewportSize from playwright._impl._browser import Browser as BrowserImpl from playwright._impl._browser_context import BrowserContext as BrowserContextImpl from playwright._impl._browser_type import BrowserType as BrowserTypeImpl from playwright._impl._cdp_session import CDPSession as CDPSessionImpl from playwright._impl._chromium_browser_context import ChromiumBrowserContext as ChromiumBrowserContextImpl from playwright._impl._console_message import ConsoleMessage as ConsoleMessageImpl from playwright._impl._dialog import Dialog as DialogImpl from playwright._impl._download import Download as DownloadImpl from playwright._impl._element_handle import ElementHandle as ElementHandleImpl from playwright._impl._file_chooser import FileChooser as FileChooserImpl from playwright._impl._frame import Frame as FrameImpl from playwright._impl._input import Keyboard as KeyboardImpl, Mouse as MouseImpl, Touchscreen as TouchscreenImpl from playwright._impl._js_handle import JSHandle as JSHandleImpl from playwright._impl._network import Request as RequestImpl, Response as ResponseImpl, Route as RouteImpl, WebSocket as WebSocketImpl from playwright._impl._page import Page as PageImpl, Worker as WorkerImpl from playwright._impl._playwright import Playwright as PlaywrightImpl from playwright._impl._selectors import Selectors as SelectorsImpl from playwright._impl._video import Video as VideoImpl from playwright._impl._logger import log_api """ all_types = [ Request, Response, Route, WebSocket, Keyboard, Mouse, Touchscreen, JSHandle, ElementHandle, Accessibility, FileChooser, Frame, Worker, Selectors, ConsoleMessage, Dialog, Download, Video, Page, BrowserContext, CDPSession, ChromiumBrowserContext, Browser, BrowserType, Playwright, ] api_globals = globals() assert Serializable |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |