_api_structures.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. # Copyright (c) Microsoft Corporation.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. from typing import Any, Dict, List, Literal, Optional, Sequence, TypedDict, Union
  16. # These are the structures that we like keeping in a JSON form for their potential
  17. # reuse between SDKs / services. They are public and are a part of the
  18. # stable API.
  19. # Explicitly mark optional params as such for the documentation
  20. # If there is at least one optional param, set total=False for better mypy handling.
  21. class Cookie(TypedDict, total=False):
  22. name: str
  23. value: str
  24. domain: str
  25. path: str
  26. expires: float
  27. httpOnly: bool
  28. secure: bool
  29. sameSite: Literal["Lax", "None", "Strict"]
  30. partitionKey: Optional[str]
  31. class StorageStateCookie(TypedDict, total=False):
  32. name: str
  33. value: str
  34. domain: str
  35. path: str
  36. expires: float
  37. httpOnly: bool
  38. secure: bool
  39. sameSite: Literal["Lax", "None", "Strict"]
  40. # TODO: We are waiting for PEP705 so SetCookieParam can be readonly and matches Cookie.
  41. class SetCookieParam(TypedDict, total=False):
  42. name: str
  43. value: str
  44. url: Optional[str]
  45. domain: Optional[str]
  46. path: Optional[str]
  47. expires: Optional[float]
  48. httpOnly: Optional[bool]
  49. secure: Optional[bool]
  50. sameSite: Optional[Literal["Lax", "None", "Strict"]]
  51. partitionKey: Optional[str]
  52. class FloatRect(TypedDict):
  53. x: float
  54. y: float
  55. width: float
  56. height: float
  57. class Geolocation(TypedDict, total=False):
  58. latitude: float
  59. longitude: float
  60. accuracy: Optional[float]
  61. class HttpCredentials(TypedDict, total=False):
  62. username: str
  63. password: str
  64. origin: Optional[str]
  65. send: Optional[Literal["always", "unauthorized"]]
  66. class LocalStorageEntry(TypedDict):
  67. name: str
  68. value: str
  69. class OriginState(TypedDict):
  70. origin: str
  71. localStorage: List[LocalStorageEntry]
  72. class PdfMargins(TypedDict, total=False):
  73. top: Optional[Union[str, float]]
  74. right: Optional[Union[str, float]]
  75. bottom: Optional[Union[str, float]]
  76. left: Optional[Union[str, float]]
  77. class Position(TypedDict):
  78. x: float
  79. y: float
  80. class ProxySettings(TypedDict, total=False):
  81. server: str
  82. bypass: Optional[str]
  83. username: Optional[str]
  84. password: Optional[str]
  85. class StorageState(TypedDict, total=False):
  86. cookies: List[StorageStateCookie]
  87. origins: List[OriginState]
  88. class ClientCertificate(TypedDict, total=False):
  89. origin: str
  90. certPath: Optional[Union[str, Path]]
  91. cert: Optional[bytes]
  92. keyPath: Optional[Union[str, Path]]
  93. key: Optional[bytes]
  94. pfxPath: Optional[Union[str, Path]]
  95. pfx: Optional[bytes]
  96. passphrase: Optional[str]
  97. class ResourceTiming(TypedDict):
  98. startTime: float
  99. domainLookupStart: float
  100. domainLookupEnd: float
  101. connectStart: float
  102. secureConnectionStart: float
  103. connectEnd: float
  104. requestStart: float
  105. responseStart: float
  106. responseEnd: float
  107. class RequestSizes(TypedDict):
  108. requestBodySize: int
  109. requestHeadersSize: int
  110. responseBodySize: int
  111. responseHeadersSize: int
  112. class ViewportSize(TypedDict):
  113. width: int
  114. height: int
  115. class SourceLocation(TypedDict):
  116. url: str
  117. lineNumber: int
  118. columnNumber: int
  119. class FilePayload(TypedDict):
  120. name: str
  121. mimeType: str
  122. buffer: bytes
  123. class RemoteAddr(TypedDict):
  124. ipAddress: str
  125. port: int
  126. class SecurityDetails(TypedDict):
  127. issuer: Optional[str]
  128. protocol: Optional[str]
  129. subjectName: Optional[str]
  130. validFrom: Optional[float]
  131. validTo: Optional[float]
  132. class NameValue(TypedDict):
  133. name: str
  134. value: str
  135. HeadersArray = List[NameValue]
  136. Headers = Dict[str, str]
  137. class ServerFilePayload(TypedDict):
  138. name: str
  139. mimeType: str
  140. buffer: str
  141. class FormField(TypedDict, total=False):
  142. name: str
  143. value: Optional[str]
  144. file: Optional[ServerFilePayload]
  145. class ExpectedTextValue(TypedDict, total=False):
  146. string: str
  147. regexSource: str
  148. regexFlags: str
  149. matchSubstring: bool
  150. normalizeWhiteSpace: bool
  151. ignoreCase: Optional[bool]
  152. class FrameExpectOptions(TypedDict, total=False):
  153. expressionArg: Any
  154. expectedText: Optional[Sequence[ExpectedTextValue]]
  155. expectedNumber: Optional[float]
  156. expectedValue: Optional[Any]
  157. useInnerText: Optional[bool]
  158. isNot: bool
  159. timeout: Optional[float]
  160. class FrameExpectResult(TypedDict):
  161. matches: bool
  162. received: Any
  163. log: List[str]
  164. errorMessage: Optional[str]
  165. AriaRole = Literal[
  166. "alert",
  167. "alertdialog",
  168. "application",
  169. "article",
  170. "banner",
  171. "blockquote",
  172. "button",
  173. "caption",
  174. "cell",
  175. "checkbox",
  176. "code",
  177. "columnheader",
  178. "combobox",
  179. "complementary",
  180. "contentinfo",
  181. "definition",
  182. "deletion",
  183. "dialog",
  184. "directory",
  185. "document",
  186. "emphasis",
  187. "feed",
  188. "figure",
  189. "form",
  190. "generic",
  191. "grid",
  192. "gridcell",
  193. "group",
  194. "heading",
  195. "img",
  196. "insertion",
  197. "link",
  198. "list",
  199. "listbox",
  200. "listitem",
  201. "log",
  202. "main",
  203. "marquee",
  204. "math",
  205. "menu",
  206. "menubar",
  207. "menuitem",
  208. "menuitemcheckbox",
  209. "menuitemradio",
  210. "meter",
  211. "navigation",
  212. "none",
  213. "note",
  214. "option",
  215. "paragraph",
  216. "presentation",
  217. "progressbar",
  218. "radio",
  219. "radiogroup",
  220. "region",
  221. "row",
  222. "rowgroup",
  223. "rowheader",
  224. "scrollbar",
  225. "search",
  226. "searchbox",
  227. "separator",
  228. "slider",
  229. "spinbutton",
  230. "status",
  231. "strong",
  232. "subscript",
  233. "superscript",
  234. "switch",
  235. "tab",
  236. "table",
  237. "tablist",
  238. "tabpanel",
  239. "term",
  240. "textbox",
  241. "time",
  242. "timer",
  243. "toolbar",
  244. "tooltip",
  245. "tree",
  246. "treegrid",
  247. "treeitem",
  248. ]
  249. class TracingGroupLocation(TypedDict):
  250. file: str
  251. line: Optional[int]
  252. column: Optional[int]