Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,27 @@ def format_annotation(current_module: types.ModuleType, ann: typing.Any):
ann_str = f'{ann.__module__}.{ann.__name__}'
else:
ann_str = ann.__name__
elif ann._name == 'Any':
elif hasattr(ann, '_name') and ann._name == 'Any':
ann_str = 'typing.Any'
elif ann._name == 'List':
elif hasattr(ann, '_name') and ann._name == 'List':
nested_ann = format_annotation(current_module, ann.__args__[0])
ann_str = f'typing.List[{nested_ann}]'
elif ann._name == 'Tuple':
elif hasattr(ann, '_name') and ann._name == 'Dict':
key_ann = format_annotation(current_module, ann.__args__[0])
val_ann = format_annotation(current_module, ann.__args__[1])
ann_str = f'typing.Dict[{key_ann}, {val_ann}]'
elif hasattr(ann, '_name') and ann._name == 'Tuple':
nested_anns = ', '.join(format_annotation(current_module, a) for a in ann.__args__)
ann_str = f'typing.Tuple[{nested_anns}]'
elif ann._name is None and len(ann.__args__) > 1:
elif hasattr(ann, '_name') and ann._name == 'Generator':
nested_anns = ', '.join(format_annotation(current_module, a) for a in ann.__args__)
ann_str = f'typing.Generator[{nested_anns}]'
elif hasattr(ann, '_name') and ann._name == 'Optional':
# Optional is actually Union[X, None]
opt_type = [a for a in ann.__args__ if a is not type(None)][0]
nested_ann = format_annotation(current_module, opt_type)
ann_str = f'typing.Optional[{nested_ann}]'
elif hasattr(ann, '_name') and ann._name is None and hasattr(ann, '__args__') and len(ann.__args__) > 1:
# For some reason union annotations don't have a name?
# If the union has two members and one of them is NoneType, then it's really
# a typing.Optional.
Expand Down
1,697 changes: 963 additions & 734 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.7"
chrome-devtools-protocol = "^0.4.0"
trio = "^0.13.0"
trio_websocket = "^0.8.0"
trio = "^0.22.0"
trio_websocket = "^0.9.0"

[tool.poetry.dev-dependencies]
mypy = "^0.770"
pytest = "^5.4.1"
pytest-cov = "^2.8.1"
pytest-trio = "^0.5.2"
[tool.poetry.group.dev.dependencies]
mypy = "^1.0"
pytest = "^7.0"
pytest-cov = "^4.0"
pytest-trio = "^0.8.0"
sphinx = "^3.0.1"
sphinx-rtd-theme = "^0.4.3"
sphinx-autodoc-typehints = "^1.10.3"
Expand Down
4 changes: 1 addition & 3 deletions trio_cdp/generated/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import accessibility
from . import animation
from . import application_cache
from . import audits
from . import background_service
from . import browser
Expand All @@ -20,7 +21,6 @@
from . import dom_snapshot
from . import dom_storage
from . import emulation
from . import event_breakpoints
from . import fetch
from . import headless_experimental
from . import heap_profiler
Expand All @@ -30,13 +30,11 @@
from . import io
from . import layer_tree
from . import log
from . import media
from . import memory
from . import network
from . import overlay
from . import page
from . import performance
from . import performance_timeline
from . import profiler
from . import runtime
from . import schema
Expand Down
98 changes: 4 additions & 94 deletions trio_cdp/generated/accessibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
AXValueNativeSourceType,
AXValueSource,
AXValueSourceType,
AXValueType,
LoadComplete,
NodesUpdated
AXValueType
)


Expand All @@ -42,61 +40,16 @@ async def enable() -> None:
return await session.execute(cdp.accessibility.enable())


async def get_ax_node_and_ancestors(
node_id: typing.Optional[cdp.dom.NodeId] = None,
backend_node_id: typing.Optional[cdp.dom.BackendNodeId] = None,
object_id: typing.Optional[cdp.runtime.RemoteObjectId] = None
) -> typing.List[AXNode]:
r'''
Fetches a node and all ancestors up to and including the root.
Requires ``enable()`` to have been called previously.

**EXPERIMENTAL**

:param node_id: *(Optional)* Identifier of the node to get.
:param backend_node_id: *(Optional)* Identifier of the backend node to get.
:param object_id: *(Optional)* JavaScript object id of the node wrapper to get.
:returns:
'''
session = get_session_context('accessibility.get_ax_node_and_ancestors')
return await session.execute(cdp.accessibility.get_ax_node_and_ancestors(node_id, backend_node_id, object_id))


async def get_child_ax_nodes(
id_: AXNodeId,
frame_id: typing.Optional[cdp.page.FrameId] = None
) -> typing.List[AXNode]:
r'''
Fetches a particular accessibility node by AXNodeId.
Requires ``enable()`` to have been called previously.

**EXPERIMENTAL**

:param id_:
:param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
:returns:
'''
session = get_session_context('accessibility.get_child_ax_nodes')
return await session.execute(cdp.accessibility.get_child_ax_nodes(id_, frame_id))


async def get_full_ax_tree(
depth: typing.Optional[int] = None,
max_depth: typing.Optional[int] = None,
frame_id: typing.Optional[cdp.page.FrameId] = None
) -> typing.List[AXNode]:
async def get_full_ax_tree() -> typing.List[AXNode]:
r'''
Fetches the entire accessibility tree for the root Document
Fetches the entire accessibility tree

**EXPERIMENTAL**

:param depth: *(Optional)* The maximum depth at which descendants of the root node should be retrieved. If omitted, the full tree is returned.
:param max_depth: **(DEPRECATED)** *(Optional)* Deprecated. This parameter has been renamed to ```depth```. If depth is not provided, max_depth will be used.
:param frame_id: *(Optional)* The frame for whose document the AX tree should be retrieved. If omited, the root frame is used.
:returns:
'''
session = get_session_context('accessibility.get_full_ax_tree')
return await session.execute(cdp.accessibility.get_full_ax_tree(depth, max_depth, frame_id))
return await session.execute(cdp.accessibility.get_full_ax_tree())


async def get_partial_ax_tree(
Expand All @@ -118,46 +71,3 @@ async def get_partial_ax_tree(
'''
session = get_session_context('accessibility.get_partial_ax_tree')
return await session.execute(cdp.accessibility.get_partial_ax_tree(node_id, backend_node_id, object_id, fetch_relatives))


async def get_root_ax_node(
frame_id: typing.Optional[cdp.page.FrameId] = None
) -> AXNode:
r'''
Fetches the root node.
Requires ``enable()`` to have been called previously.

**EXPERIMENTAL**

:param frame_id: *(Optional)* The frame in whose document the node resides. If omitted, the root frame is used.
:returns:
'''
session = get_session_context('accessibility.get_root_ax_node')
return await session.execute(cdp.accessibility.get_root_ax_node(frame_id))


async def query_ax_tree(
node_id: typing.Optional[cdp.dom.NodeId] = None,
backend_node_id: typing.Optional[cdp.dom.BackendNodeId] = None,
object_id: typing.Optional[cdp.runtime.RemoteObjectId] = None,
accessible_name: typing.Optional[str] = None,
role: typing.Optional[str] = None
) -> typing.List[AXNode]:
r'''
Query a DOM node's accessibility subtree for accessible name and role.
This command computes the name and role for all nodes in the subtree, including those that are
ignored for accessibility, and returns those that mactch the specified name and role. If no DOM
node is specified, or the DOM node does not exist, the command returns an error. If neither
``accessibleName`` or ``role`` is specified, it returns all the accessibility nodes in the subtree.

**EXPERIMENTAL**

:param node_id: *(Optional)* Identifier of the node for the root to query.
:param backend_node_id: *(Optional)* Identifier of the backend node for the root to query.
:param object_id: *(Optional)* JavaScript object id of the node wrapper for the root to query.
:param accessible_name: *(Optional)* Find nodes with this computed name.
:param role: *(Optional)* Find nodes with this computed role.
:returns: A list of ``Accessibility.AXNode`` matching the specified attributes, including nodes that are ignored for accessibility.
'''
session = get_session_context('accessibility.query_ax_tree')
return await session.execute(cdp.accessibility.query_ax_tree(node_id, backend_node_id, object_id, accessible_name, role))
63 changes: 63 additions & 0 deletions trio_cdp/generated/application_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.application_cache
from cdp.application_cache import (
ApplicationCache,
ApplicationCacheResource,
ApplicationCacheStatusUpdated,
FrameWithManifest,
NetworkStateUpdated
)


async def enable() -> None:
r'''
Enables application cache domain notifications.
'''
session = get_session_context('application_cache.enable')
return await session.execute(cdp.application_cache.enable())


async def get_application_cache_for_frame(
frame_id: cdp.page.FrameId
) -> ApplicationCache:
r'''
Returns relevant application cache data for the document in given frame.

:param frame_id: Identifier of the frame containing document whose application cache is retrieved.
:returns: Relevant application cache data for the document in given frame.
'''
session = get_session_context('application_cache.get_application_cache_for_frame')
return await session.execute(cdp.application_cache.get_application_cache_for_frame(frame_id))


async def get_frames_with_manifests() -> typing.List[FrameWithManifest]:
r'''
Returns array of frame identifiers with manifest urls for each frame containing a document
associated with some application cache.

:returns: Array of frame identifiers with manifest urls for each frame containing a document associated with some application cache.
'''
session = get_session_context('application_cache.get_frames_with_manifests')
return await session.execute(cdp.application_cache.get_frames_with_manifests())


async def get_manifest_for_frame(
frame_id: cdp.page.FrameId
) -> str:
r'''
Returns manifest URL for document in the given frame.

:param frame_id: Identifier of the frame containing document whose manifest is retrieved.
:returns: Manifest URL for document in the given frame.
'''
session = get_session_context('application_cache.get_manifest_for_frame')
return await session.execute(cdp.application_cache.get_manifest_for_frame(frame_id))
74 changes: 1 addition & 73 deletions trio_cdp/generated/audits.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,6 @@
from ..context import get_connection_context, get_session_context

import cdp.audits
from cdp.audits import (
AffectedCookie,
AffectedFrame,
AffectedRequest,
AttributionReportingIssueDetails,
AttributionReportingIssueType,
BlockedByResponseIssueDetails,
BlockedByResponseReason,
ClientHintIssueDetails,
ClientHintIssueReason,
ContentSecurityPolicyIssueDetails,
ContentSecurityPolicyViolationType,
CorsIssueDetails,
DeprecationIssueDetails,
GenericIssueDetails,
GenericIssueErrorType,
HeavyAdIssueDetails,
HeavyAdReason,
HeavyAdResolutionStatus,
InspectorIssue,
InspectorIssueCode,
InspectorIssueDetails,
IssueAdded,
IssueId,
LowTextContrastIssueDetails,
MixedContentIssueDetails,
MixedContentResolutionStatus,
MixedContentResourceType,
NavigatorUserAgentIssueDetails,
QuirksModeIssueDetails,
SameSiteCookieExclusionReason,
SameSiteCookieIssueDetails,
SameSiteCookieOperation,
SameSiteCookieWarningReason,
SharedArrayBufferIssueDetails,
SharedArrayBufferIssueType,
SourceCodeLocation,
TrustedWebActivityIssueDetails,
TwaQualityEnforcementViolationType,
WasmCrossOriginModuleSharingIssueDetails
)


async def check_contrast(
report_aaa: typing.Optional[bool] = None
) -> None:
r'''
Runs the contrast check for the target page. Found issues are reported
using Audits.issueAdded event.

:param report_aaa: *(Optional)* Whether to report WCAG AAA level issues. Default is false.
'''
session = get_session_context('audits.check_contrast')
return await session.execute(cdp.audits.check_contrast(report_aaa))


async def disable() -> None:
r'''
Disables issues domain, prevents further issues from being reported to the client.
'''
session = get_session_context('audits.disable')
return await session.execute(cdp.audits.disable())


async def enable() -> None:
r'''
Enables issues domain, sends the issues collected so far to the client by means of the
``issueAdded`` event.
'''
session = get_session_context('audits.enable')
return await session.execute(cdp.audits.enable())


async def get_encoded_response(
request_id: cdp.network.RequestId,
Expand All @@ -98,7 +26,7 @@ async def get_encoded_response(
:param size_only: *(Optional)* Whether to only return the size information (defaults to false).
:returns: A tuple with the following items:

0. **body** - *(Optional)* The encoded body as a base64 string. Omitted if sizeOnly is true. (Encoded as a base64 string when passed over JSON)
0. **body** - *(Optional)* The encoded body as a base64 string. Omitted if sizeOnly is true.
1. **originalSize** - Size before re-encoding.
2. **encodedSize** - Size after re-encoding.
'''
Expand Down
Loading
Loading