pybiolib 0.2.951__py3-none-any.whl → 1.2.1890__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biolib/__init__.py +357 -11
- biolib/_data_record/data_record.py +380 -0
- biolib/_index/__init__.py +0 -0
- biolib/_index/index.py +55 -0
- biolib/_index/query_result.py +103 -0
- biolib/_internal/__init__.py +0 -0
- biolib/_internal/add_copilot_prompts.py +58 -0
- biolib/_internal/add_gui_files.py +81 -0
- biolib/_internal/data_record/__init__.py +1 -0
- biolib/_internal/data_record/data_record.py +85 -0
- biolib/_internal/data_record/push_data.py +116 -0
- biolib/_internal/data_record/remote_storage_endpoint.py +43 -0
- biolib/_internal/errors.py +5 -0
- biolib/_internal/file_utils.py +125 -0
- biolib/_internal/fuse_mount/__init__.py +1 -0
- biolib/_internal/fuse_mount/experiment_fuse_mount.py +209 -0
- biolib/_internal/http_client.py +159 -0
- biolib/_internal/lfs/__init__.py +1 -0
- biolib/_internal/lfs/cache.py +51 -0
- biolib/_internal/libs/__init__.py +1 -0
- biolib/_internal/libs/fusepy/__init__.py +1257 -0
- biolib/_internal/push_application.py +488 -0
- biolib/_internal/runtime.py +22 -0
- biolib/_internal/string_utils.py +13 -0
- biolib/_internal/templates/__init__.py +1 -0
- biolib/_internal/templates/copilot_template/.github/instructions/general-app-knowledge.instructions.md +10 -0
- biolib/_internal/templates/copilot_template/.github/instructions/style-general.instructions.md +20 -0
- biolib/_internal/templates/copilot_template/.github/instructions/style-python.instructions.md +16 -0
- biolib/_internal/templates/copilot_template/.github/instructions/style-react-ts.instructions.md +47 -0
- biolib/_internal/templates/copilot_template/.github/prompts/biolib_app_inputs.prompt.md +11 -0
- biolib/_internal/templates/copilot_template/.github/prompts/biolib_onboard_repo.prompt.md +19 -0
- biolib/_internal/templates/copilot_template/.github/prompts/biolib_run_apps.prompt.md +12 -0
- biolib/_internal/templates/dashboard_template/.biolib/config.yml +5 -0
- biolib/_internal/templates/github_workflow_template/.github/workflows/biolib.yml +21 -0
- biolib/_internal/templates/gitignore_template/.gitignore +10 -0
- biolib/_internal/templates/gui_template/.yarnrc.yml +1 -0
- biolib/_internal/templates/gui_template/App.tsx +53 -0
- biolib/_internal/templates/gui_template/Dockerfile +27 -0
- biolib/_internal/templates/gui_template/biolib-sdk.ts +82 -0
- biolib/_internal/templates/gui_template/dev-data/output.json +7 -0
- biolib/_internal/templates/gui_template/index.css +5 -0
- biolib/_internal/templates/gui_template/index.html +13 -0
- biolib/_internal/templates/gui_template/index.tsx +10 -0
- biolib/_internal/templates/gui_template/package.json +27 -0
- biolib/_internal/templates/gui_template/tsconfig.json +24 -0
- biolib/_internal/templates/gui_template/vite-plugin-dev-data.ts +50 -0
- biolib/_internal/templates/gui_template/vite.config.mts +10 -0
- biolib/_internal/templates/init_template/.biolib/config.yml +19 -0
- biolib/_internal/templates/init_template/Dockerfile +14 -0
- biolib/_internal/templates/init_template/requirements.txt +1 -0
- biolib/_internal/templates/init_template/run.py +12 -0
- biolib/_internal/templates/init_template/run.sh +4 -0
- biolib/_internal/templates/templates.py +25 -0
- biolib/_internal/tree_utils.py +106 -0
- biolib/_internal/utils/__init__.py +65 -0
- biolib/_internal/utils/auth.py +46 -0
- biolib/_internal/utils/job_url.py +33 -0
- biolib/_internal/utils/multinode.py +263 -0
- biolib/_runtime/runtime.py +157 -0
- biolib/_session/session.py +44 -0
- biolib/_shared/__init__.py +0 -0
- biolib/_shared/types/__init__.py +74 -0
- biolib/_shared/types/account.py +12 -0
- biolib/_shared/types/account_member.py +8 -0
- biolib/_shared/types/app.py +9 -0
- biolib/_shared/types/data_record.py +40 -0
- biolib/_shared/types/experiment.py +32 -0
- biolib/_shared/types/file_node.py +17 -0
- biolib/_shared/types/push.py +6 -0
- biolib/_shared/types/resource.py +37 -0
- biolib/_shared/types/resource_deploy_key.py +11 -0
- biolib/_shared/types/resource_permission.py +14 -0
- biolib/_shared/types/resource_version.py +19 -0
- biolib/_shared/types/result.py +14 -0
- biolib/_shared/types/typing.py +10 -0
- biolib/_shared/types/user.py +19 -0
- biolib/_shared/utils/__init__.py +7 -0
- biolib/_shared/utils/resource_uri.py +75 -0
- biolib/api/__init__.py +6 -0
- biolib/api/client.py +168 -0
- biolib/app/app.py +252 -49
- biolib/app/search_apps.py +45 -0
- biolib/biolib_api_client/api_client.py +126 -31
- biolib/biolib_api_client/app_types.py +24 -4
- biolib/biolib_api_client/auth.py +31 -8
- biolib/biolib_api_client/biolib_app_api.py +147 -52
- biolib/biolib_api_client/biolib_job_api.py +161 -141
- biolib/biolib_api_client/job_types.py +21 -5
- biolib/biolib_api_client/lfs_types.py +7 -23
- biolib/biolib_api_client/user_state.py +56 -0
- biolib/biolib_binary_format/__init__.py +1 -4
- biolib/biolib_binary_format/file_in_container.py +105 -0
- biolib/biolib_binary_format/module_input.py +24 -7
- biolib/biolib_binary_format/module_output_v2.py +149 -0
- biolib/biolib_binary_format/remote_endpoints.py +34 -0
- biolib/biolib_binary_format/remote_stream_seeker.py +59 -0
- biolib/biolib_binary_format/saved_job.py +3 -2
- biolib/biolib_binary_format/{attestation_document.py → stdout_and_stderr.py} +8 -8
- biolib/biolib_binary_format/system_status_update.py +3 -2
- biolib/biolib_binary_format/utils.py +175 -0
- biolib/biolib_docker_client/__init__.py +11 -2
- biolib/biolib_errors.py +36 -0
- biolib/biolib_logging.py +27 -10
- biolib/cli/__init__.py +38 -0
- biolib/cli/auth.py +46 -0
- biolib/cli/data_record.py +164 -0
- biolib/cli/index.py +32 -0
- biolib/cli/init.py +421 -0
- biolib/cli/lfs.py +101 -0
- biolib/cli/push.py +50 -0
- biolib/cli/run.py +63 -0
- biolib/cli/runtime.py +14 -0
- biolib/cli/sdk.py +16 -0
- biolib/cli/start.py +56 -0
- biolib/compute_node/cloud_utils/cloud_utils.py +110 -161
- biolib/compute_node/job_worker/cache_state.py +66 -88
- biolib/compute_node/job_worker/cache_types.py +1 -6
- biolib/compute_node/job_worker/docker_image_cache.py +112 -37
- biolib/compute_node/job_worker/executors/__init__.py +0 -3
- biolib/compute_node/job_worker/executors/docker_executor.py +532 -199
- biolib/compute_node/job_worker/executors/docker_types.py +9 -1
- biolib/compute_node/job_worker/executors/types.py +19 -9
- biolib/compute_node/job_worker/job_legacy_input_wait_timeout_thread.py +30 -0
- biolib/compute_node/job_worker/job_max_runtime_timer_thread.py +3 -5
- biolib/compute_node/job_worker/job_storage.py +108 -0
- biolib/compute_node/job_worker/job_worker.py +397 -212
- biolib/compute_node/job_worker/large_file_system.py +87 -38
- biolib/compute_node/job_worker/network_alloc.py +99 -0
- biolib/compute_node/job_worker/network_buffer.py +240 -0
- biolib/compute_node/job_worker/utilization_reporter_thread.py +197 -0
- biolib/compute_node/job_worker/utils.py +9 -24
- biolib/compute_node/remote_host_proxy.py +400 -98
- biolib/compute_node/utils.py +31 -9
- biolib/compute_node/webserver/compute_node_results_proxy.py +189 -0
- biolib/compute_node/webserver/proxy_utils.py +28 -0
- biolib/compute_node/webserver/webserver.py +130 -44
- biolib/compute_node/webserver/webserver_types.py +2 -6
- biolib/compute_node/webserver/webserver_utils.py +77 -12
- biolib/compute_node/webserver/worker_thread.py +183 -42
- biolib/experiments/__init__.py +0 -0
- biolib/experiments/experiment.py +356 -0
- biolib/jobs/__init__.py +1 -0
- biolib/jobs/job.py +741 -0
- biolib/jobs/job_result.py +185 -0
- biolib/jobs/types.py +50 -0
- biolib/py.typed +0 -0
- biolib/runtime/__init__.py +14 -0
- biolib/sdk/__init__.py +91 -0
- biolib/tables.py +34 -0
- biolib/typing_utils.py +2 -7
- biolib/user/__init__.py +1 -0
- biolib/user/sign_in.py +54 -0
- biolib/utils/__init__.py +162 -0
- biolib/utils/cache_state.py +94 -0
- biolib/utils/multipart_uploader.py +194 -0
- biolib/utils/seq_util.py +150 -0
- biolib/utils/zip/remote_zip.py +640 -0
- pybiolib-1.2.1890.dist-info/METADATA +41 -0
- pybiolib-1.2.1890.dist-info/RECORD +177 -0
- {pybiolib-0.2.951.dist-info → pybiolib-1.2.1890.dist-info}/WHEEL +1 -1
- pybiolib-1.2.1890.dist-info/entry_points.txt +2 -0
- README.md +0 -17
- biolib/app/app_result.py +0 -68
- biolib/app/utils.py +0 -62
- biolib/biolib-js/0-biolib.worker.js +0 -1
- biolib/biolib-js/1-biolib.worker.js +0 -1
- biolib/biolib-js/2-biolib.worker.js +0 -1
- biolib/biolib-js/3-biolib.worker.js +0 -1
- biolib/biolib-js/4-biolib.worker.js +0 -1
- biolib/biolib-js/5-biolib.worker.js +0 -1
- biolib/biolib-js/6-biolib.worker.js +0 -1
- biolib/biolib-js/index.html +0 -10
- biolib/biolib-js/main-biolib.js +0 -1
- biolib/biolib_api_client/biolib_account_api.py +0 -21
- biolib/biolib_api_client/biolib_large_file_system_api.py +0 -108
- biolib/biolib_binary_format/aes_encrypted_package.py +0 -42
- biolib/biolib_binary_format/module_output.py +0 -58
- biolib/biolib_binary_format/rsa_encrypted_aes_package.py +0 -57
- biolib/biolib_push.py +0 -114
- biolib/cli.py +0 -203
- biolib/cli_utils.py +0 -273
- biolib/compute_node/cloud_utils/enclave_parent_types.py +0 -7
- biolib/compute_node/enclave/__init__.py +0 -2
- biolib/compute_node/enclave/enclave_remote_hosts.py +0 -53
- biolib/compute_node/enclave/nitro_secure_module_utils.py +0 -64
- biolib/compute_node/job_worker/executors/base_executor.py +0 -18
- biolib/compute_node/job_worker/executors/pyppeteer_executor.py +0 -173
- biolib/compute_node/job_worker/executors/remote/__init__.py +0 -1
- biolib/compute_node/job_worker/executors/remote/nitro_enclave_utils.py +0 -81
- biolib/compute_node/job_worker/executors/remote/remote_executor.py +0 -51
- biolib/lfs.py +0 -196
- biolib/pyppeteer/.circleci/config.yml +0 -100
- biolib/pyppeteer/.coveragerc +0 -3
- biolib/pyppeteer/.gitignore +0 -89
- biolib/pyppeteer/.pre-commit-config.yaml +0 -28
- biolib/pyppeteer/CHANGES.md +0 -253
- biolib/pyppeteer/CONTRIBUTING.md +0 -26
- biolib/pyppeteer/LICENSE +0 -12
- biolib/pyppeteer/README.md +0 -137
- biolib/pyppeteer/docs/Makefile +0 -177
- biolib/pyppeteer/docs/_static/custom.css +0 -28
- biolib/pyppeteer/docs/_templates/layout.html +0 -10
- biolib/pyppeteer/docs/changes.md +0 -1
- biolib/pyppeteer/docs/conf.py +0 -299
- biolib/pyppeteer/docs/index.md +0 -21
- biolib/pyppeteer/docs/make.bat +0 -242
- biolib/pyppeteer/docs/reference.md +0 -211
- biolib/pyppeteer/docs/server.py +0 -60
- biolib/pyppeteer/poetry.lock +0 -1699
- biolib/pyppeteer/pyppeteer/__init__.py +0 -135
- biolib/pyppeteer/pyppeteer/accessibility.py +0 -286
- biolib/pyppeteer/pyppeteer/browser.py +0 -401
- biolib/pyppeteer/pyppeteer/browser_fetcher.py +0 -194
- biolib/pyppeteer/pyppeteer/command.py +0 -22
- biolib/pyppeteer/pyppeteer/connection/__init__.py +0 -242
- biolib/pyppeteer/pyppeteer/connection/cdpsession.py +0 -101
- biolib/pyppeteer/pyppeteer/coverage.py +0 -346
- biolib/pyppeteer/pyppeteer/device_descriptors.py +0 -787
- biolib/pyppeteer/pyppeteer/dialog.py +0 -79
- biolib/pyppeteer/pyppeteer/domworld.py +0 -597
- biolib/pyppeteer/pyppeteer/emulation_manager.py +0 -53
- biolib/pyppeteer/pyppeteer/errors.py +0 -48
- biolib/pyppeteer/pyppeteer/events.py +0 -63
- biolib/pyppeteer/pyppeteer/execution_context.py +0 -156
- biolib/pyppeteer/pyppeteer/frame/__init__.py +0 -299
- biolib/pyppeteer/pyppeteer/frame/frame_manager.py +0 -306
- biolib/pyppeteer/pyppeteer/helpers.py +0 -245
- biolib/pyppeteer/pyppeteer/input.py +0 -371
- biolib/pyppeteer/pyppeteer/jshandle.py +0 -598
- biolib/pyppeteer/pyppeteer/launcher.py +0 -683
- biolib/pyppeteer/pyppeteer/lifecycle_watcher.py +0 -169
- biolib/pyppeteer/pyppeteer/models/__init__.py +0 -103
- biolib/pyppeteer/pyppeteer/models/_protocol.py +0 -12460
- biolib/pyppeteer/pyppeteer/multimap.py +0 -82
- biolib/pyppeteer/pyppeteer/network_manager.py +0 -678
- biolib/pyppeteer/pyppeteer/options.py +0 -8
- biolib/pyppeteer/pyppeteer/page.py +0 -1728
- biolib/pyppeteer/pyppeteer/pipe_transport.py +0 -59
- biolib/pyppeteer/pyppeteer/target.py +0 -147
- biolib/pyppeteer/pyppeteer/task_queue.py +0 -24
- biolib/pyppeteer/pyppeteer/timeout_settings.py +0 -36
- biolib/pyppeteer/pyppeteer/tracing.py +0 -93
- biolib/pyppeteer/pyppeteer/us_keyboard_layout.py +0 -305
- biolib/pyppeteer/pyppeteer/util.py +0 -18
- biolib/pyppeteer/pyppeteer/websocket_transport.py +0 -47
- biolib/pyppeteer/pyppeteer/worker.py +0 -101
- biolib/pyppeteer/pyproject.toml +0 -97
- biolib/pyppeteer/spell.txt +0 -137
- biolib/pyppeteer/tox.ini +0 -72
- biolib/pyppeteer/utils/generate_protocol_types.py +0 -603
- biolib/start_cli.py +0 -7
- biolib/utils.py +0 -47
- biolib/validators/validate_app_version.py +0 -183
- biolib/validators/validate_argument.py +0 -134
- biolib/validators/validate_module.py +0 -323
- biolib/validators/validate_zip_file.py +0 -40
- biolib/validators/validator_utils.py +0 -103
- pybiolib-0.2.951.dist-info/LICENSE +0 -21
- pybiolib-0.2.951.dist-info/METADATA +0 -61
- pybiolib-0.2.951.dist-info/RECORD +0 -153
- pybiolib-0.2.951.dist-info/entry_points.txt +0 -3
- /LICENSE → /pybiolib-1.2.1890.dist-info/licenses/LICENSE +0 -0
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
|
|
4
|
-
"""
|
|
5
|
-
Keyboard and Mouse module
|
|
6
|
-
|
|
7
|
-
puppeteer equivalent: lib/Input.js
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import asyncio
|
|
11
|
-
from typing import TYPE_CHECKING, Dict
|
|
12
|
-
|
|
13
|
-
from biolib.pyppeteer.pyppeteer.connection import CDPSession
|
|
14
|
-
from biolib.pyppeteer.pyppeteer.errors import PyppeteerError
|
|
15
|
-
from biolib.pyppeteer.pyppeteer.us_keyboard_layout import keyDefinitions
|
|
16
|
-
|
|
17
|
-
if TYPE_CHECKING:
|
|
18
|
-
from typing import Set
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class Keyboard:
|
|
22
|
-
"""Keyboard class provides as api for managing a virtual keyboard.
|
|
23
|
-
|
|
24
|
-
The high level api is :meth:`type`, which takes raw characters and
|
|
25
|
-
generate proper keydown, keypress/input, and keyup events on your page.
|
|
26
|
-
|
|
27
|
-
For finer control, you can use :meth:`down`, :meth:`up`, and
|
|
28
|
-
:meth:`sendCharacter` to manually fire events as if they were generated
|
|
29
|
-
from a real keyboard.
|
|
30
|
-
|
|
31
|
-
An example of holding down ``Shift`` in order to select and delete some
|
|
32
|
-
text:
|
|
33
|
-
|
|
34
|
-
.. code::
|
|
35
|
-
|
|
36
|
-
await page.keyboard.type('Hello, World!')
|
|
37
|
-
await page.keyboard.press('ArrowLeft')
|
|
38
|
-
|
|
39
|
-
await page.keyboard.down('Shift')
|
|
40
|
-
for i in ' World':
|
|
41
|
-
await page.keyboard.press('ArrowLeft')
|
|
42
|
-
await page.keyboard.up('Shift')
|
|
43
|
-
|
|
44
|
-
await page.keyboard.press('Backspace')
|
|
45
|
-
# Result text will end up saying 'Hello!'.
|
|
46
|
-
|
|
47
|
-
An example of pressing ``A``:
|
|
48
|
-
|
|
49
|
-
.. code::
|
|
50
|
-
|
|
51
|
-
await page.keyboard.down('Shift')
|
|
52
|
-
await page.keyboard.press('KeyA')
|
|
53
|
-
await page.keyboard.up('Shift')
|
|
54
|
-
"""
|
|
55
|
-
|
|
56
|
-
def __init__(self, client: CDPSession) -> None:
|
|
57
|
-
self._client = client
|
|
58
|
-
self._modifiers = 0
|
|
59
|
-
self._pressedKeys: Set[str] = set()
|
|
60
|
-
|
|
61
|
-
async def down(self, key: str, text: str = None) -> None:
|
|
62
|
-
"""Dispatch a ``keydown`` event with ``key``.
|
|
63
|
-
|
|
64
|
-
If ``key`` is a single character and no modifier keys besides ``Shift``
|
|
65
|
-
are being held down, and a ``keypress``/``input`` event will also
|
|
66
|
-
generated. The ``text`` option can be specified to force an ``input``
|
|
67
|
-
event to be generated.
|
|
68
|
-
|
|
69
|
-
If ``key`` is a modifier key, like ``Shift``, ``Meta``, or ``Alt``,
|
|
70
|
-
subsequent key presses will be sent with that modifier active. To
|
|
71
|
-
release the modifier key, use :meth:`up` method.
|
|
72
|
-
|
|
73
|
-
:arg key: Name of key to press, such as ``ArrowLeft``.
|
|
74
|
-
:arg text: generate an input event with this text.
|
|
75
|
-
|
|
76
|
-
.. note::
|
|
77
|
-
Modifier keys DO influence :meth:`down`. Holding down ``shift``
|
|
78
|
-
will type the text in upper case.
|
|
79
|
-
"""
|
|
80
|
-
|
|
81
|
-
description = self._keyDescriptionForString(key)
|
|
82
|
-
autoRepeat = description['code'] in self._pressedKeys
|
|
83
|
-
self._pressedKeys.add(description['code'])
|
|
84
|
-
self._modifiers |= self._modifierBit(description['key'])
|
|
85
|
-
|
|
86
|
-
text = text or description['text']
|
|
87
|
-
|
|
88
|
-
await self._client.send(
|
|
89
|
-
'Input.dispatchKeyEvent',
|
|
90
|
-
{
|
|
91
|
-
'type': 'keyDown' if text else 'rawKeyDown',
|
|
92
|
-
'modifiers': self._modifiers,
|
|
93
|
-
'windowsVirtualKeyCode': description['keyCode'],
|
|
94
|
-
'code': description['code'],
|
|
95
|
-
'key': description['key'],
|
|
96
|
-
'text': text,
|
|
97
|
-
'unmodifiedText': text,
|
|
98
|
-
'autoRepeat': autoRepeat,
|
|
99
|
-
'location': description['location'],
|
|
100
|
-
'isKeypad': description['location'] == 3,
|
|
101
|
-
},
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
def _modifierBit(self, key: str) -> int:
|
|
105
|
-
if key == 'Alt':
|
|
106
|
-
return 1
|
|
107
|
-
if key == 'Control':
|
|
108
|
-
return 2
|
|
109
|
-
if key == 'Meta':
|
|
110
|
-
return 4
|
|
111
|
-
if key == 'Shift':
|
|
112
|
-
return 8
|
|
113
|
-
return 0
|
|
114
|
-
|
|
115
|
-
def _keyDescriptionForString(self, keyString: str) -> Dict: # noqa: C901
|
|
116
|
-
shift = self._modifiers & 8
|
|
117
|
-
description = {
|
|
118
|
-
'key': '',
|
|
119
|
-
'keyCode': 0,
|
|
120
|
-
'code': '',
|
|
121
|
-
'text': '',
|
|
122
|
-
'location': 0,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
definition: Dict = keyDefinitions.get(keyString) # type: ignore
|
|
126
|
-
if not definition:
|
|
127
|
-
raise PyppeteerError(f'Unknown key: "{keyString}"')
|
|
128
|
-
|
|
129
|
-
if definition.get('key'):
|
|
130
|
-
description['key'] = definition['key']
|
|
131
|
-
if shift and definition.get('shiftKey'):
|
|
132
|
-
description['key'] = definition['shiftKey']
|
|
133
|
-
|
|
134
|
-
if definition.get('keyCode'):
|
|
135
|
-
description['keyCode'] = definition['keyCode']
|
|
136
|
-
if shift and definition.get('shiftKeyCode'):
|
|
137
|
-
description['keyCode'] = definition['shiftKeyCode']
|
|
138
|
-
|
|
139
|
-
if definition.get('code'):
|
|
140
|
-
description['code'] = definition['code']
|
|
141
|
-
|
|
142
|
-
if definition.get('location'):
|
|
143
|
-
description['location'] = definition['location']
|
|
144
|
-
|
|
145
|
-
if len(description['key']) == 1: # type: ignore
|
|
146
|
-
description['text'] = description['key']
|
|
147
|
-
|
|
148
|
-
if definition.get('text'):
|
|
149
|
-
description['text'] = definition['text']
|
|
150
|
-
if shift and definition.get('shiftText'):
|
|
151
|
-
description['text'] = definition['shiftText']
|
|
152
|
-
|
|
153
|
-
# if any modifiers besides shift are pressed, no text should be sent
|
|
154
|
-
if self._modifiers & ~8:
|
|
155
|
-
description['text'] = ''
|
|
156
|
-
|
|
157
|
-
return description
|
|
158
|
-
|
|
159
|
-
async def up(self, key: str) -> None:
|
|
160
|
-
"""Dispatch a ``keyup`` event of the ``key``.
|
|
161
|
-
|
|
162
|
-
:arg str key: Name of key to release, such as ``ArrowLeft``.
|
|
163
|
-
"""
|
|
164
|
-
description = self._keyDescriptionForString(key)
|
|
165
|
-
|
|
166
|
-
self._modifiers &= ~self._modifierBit(description['key'])
|
|
167
|
-
if description['code'] in self._pressedKeys:
|
|
168
|
-
self._pressedKeys.remove(description['code'])
|
|
169
|
-
await self._client.send(
|
|
170
|
-
'Input.dispatchKeyEvent',
|
|
171
|
-
{
|
|
172
|
-
'type': 'keyUp',
|
|
173
|
-
'modifiers': self._modifiers,
|
|
174
|
-
'key': description['key'],
|
|
175
|
-
'windowsVirtualKeyCode': description['keyCode'],
|
|
176
|
-
'code': description['code'],
|
|
177
|
-
'location': description['location'],
|
|
178
|
-
},
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
async def sendCharacter(self, char: str) -> None:
|
|
182
|
-
"""Send character into the page.
|
|
183
|
-
|
|
184
|
-
This method dispatches a ``keypress`` and ``input`` event. This does
|
|
185
|
-
not send a ``keydown`` or ``keyup`` event.
|
|
186
|
-
|
|
187
|
-
.. note::
|
|
188
|
-
Modifier keys DO NOT effect :meth:`sendCharacter`. Holding down
|
|
189
|
-
``shift`` will not type the text in upper case.
|
|
190
|
-
"""
|
|
191
|
-
await self._client.send('Input.insertText', {'text': char})
|
|
192
|
-
|
|
193
|
-
async def type(self, text: str, delay: float = 0) -> None:
|
|
194
|
-
"""Type characters into a focused element.
|
|
195
|
-
|
|
196
|
-
This method sends ``keydown``, ``keypress``/``input``, and ``keyup``
|
|
197
|
-
event for each character in the ``text``.
|
|
198
|
-
|
|
199
|
-
To press a special key, like ``Control`` or ``ArrowDown``, use
|
|
200
|
-
:meth:`press` method.
|
|
201
|
-
|
|
202
|
-
:arg text: Text to type into a focused element.
|
|
203
|
-
:arg delay: Specifies time to wait between key presses in milliseconds, defaults
|
|
204
|
-
to 0.
|
|
205
|
-
|
|
206
|
-
.. note::
|
|
207
|
-
Modifier keys DO NOT effect :meth:`type`. Holding down ``shift``
|
|
208
|
-
will not type the text in upper case.
|
|
209
|
-
"""
|
|
210
|
-
for char in text:
|
|
211
|
-
if char in keyDefinitions:
|
|
212
|
-
await self.press(char, delay=delay)
|
|
213
|
-
else:
|
|
214
|
-
if delay:
|
|
215
|
-
await asyncio.sleep(delay / 1000)
|
|
216
|
-
await self.sendCharacter(char)
|
|
217
|
-
|
|
218
|
-
async def press(self, key: str, text: str = None, delay: float = 0) -> None:
|
|
219
|
-
"""Press ``key``.
|
|
220
|
-
|
|
221
|
-
If ``key`` is a single character and no modifier keys besides
|
|
222
|
-
``Shift`` are being held down, a ``keypress``/``input`` event will also
|
|
223
|
-
generated. The ``text`` option can be specified to force an input event
|
|
224
|
-
to be generated.
|
|
225
|
-
|
|
226
|
-
:arg key: Name of key to press, such as ``ArrowLeft``.
|
|
227
|
-
:arg text: If specified, generates an input event with this
|
|
228
|
-
text.
|
|
229
|
-
:arg delay: Time to wait between ``keydown`` and
|
|
230
|
-
``keyup``. Defaults to 0.
|
|
231
|
-
|
|
232
|
-
.. note::
|
|
233
|
-
Modifier keys DO effect :meth:`press`. Holding down ``Shift`` will
|
|
234
|
-
type the text in upper case.
|
|
235
|
-
"""
|
|
236
|
-
|
|
237
|
-
await self.down(key, text)
|
|
238
|
-
if delay:
|
|
239
|
-
await asyncio.sleep(delay / 1000)
|
|
240
|
-
await self.up(key)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
class Mouse:
|
|
244
|
-
"""Mouse class.
|
|
245
|
-
|
|
246
|
-
The :class:`Mouse` operates in main-frame CSS pixels relative to the
|
|
247
|
-
top-left corner of the viewport.
|
|
248
|
-
"""
|
|
249
|
-
|
|
250
|
-
def __init__(self, client: CDPSession, keyboard: Keyboard) -> None:
|
|
251
|
-
self._client = client
|
|
252
|
-
self._keyboard = keyboard
|
|
253
|
-
self._x = 0.0
|
|
254
|
-
self._y = 0.0
|
|
255
|
-
self._button = 'none'
|
|
256
|
-
|
|
257
|
-
async def move(self, x: float, y: float, steps: int = 1) -> None:
|
|
258
|
-
"""Move mouse cursor (dispatches a ``mousemove`` event).
|
|
259
|
-
|
|
260
|
-
:arg x: x-coordinate to move to
|
|
261
|
-
:arg y: y-coordinate to move to
|
|
262
|
-
:arg steps: number of steps to break movement into
|
|
263
|
-
"""
|
|
264
|
-
fromX = self._x
|
|
265
|
-
fromY = self._y
|
|
266
|
-
self._x = x
|
|
267
|
-
self._y = y
|
|
268
|
-
for i in range(1, steps + 1):
|
|
269
|
-
await self._client.send(
|
|
270
|
-
'Input.dispatchMouseEvent',
|
|
271
|
-
{
|
|
272
|
-
'type': 'mouseMoved',
|
|
273
|
-
'button': self._button,
|
|
274
|
-
'x': round(fromX + (self._x - fromX) * (i / steps)),
|
|
275
|
-
'y': round(fromY + (self._y - fromY) * (i / steps)),
|
|
276
|
-
'modifiers': self._keyboard._modifiers,
|
|
277
|
-
},
|
|
278
|
-
)
|
|
279
|
-
|
|
280
|
-
async def click(
|
|
281
|
-
self, x: float, y: float, button: str = 'left', clickCount: int = 1, delay: float = 0, steps: int = 1,
|
|
282
|
-
) -> None:
|
|
283
|
-
"""Click mouse button at (``x``, ``y``).
|
|
284
|
-
|
|
285
|
-
Shortcut to :meth:`move`, :meth:`down`, and :meth:`up`.
|
|
286
|
-
|
|
287
|
-
:arg x: x coordinate to click
|
|
288
|
-
:arg y: y coordinate to click
|
|
289
|
-
:arg button: mouse button to use, one of ``left``, ``right``, or ``middle``, defaults to ``left``
|
|
290
|
-
:arg clickCount: number of times to click, defaults to 1
|
|
291
|
-
:arg delay: delay in ms between mouseDown and mouseUp events, defaults to 0
|
|
292
|
-
:arg steps: steps to break mouse movement into, defaults to 1
|
|
293
|
-
|
|
294
|
-
"""
|
|
295
|
-
await self.move(x, y, steps)
|
|
296
|
-
await self.down(button, clickCount)
|
|
297
|
-
if delay:
|
|
298
|
-
await asyncio.sleep(delay / 1000)
|
|
299
|
-
await self.up(button, clickCount)
|
|
300
|
-
|
|
301
|
-
async def down(self, button: str = 'left', clickCount: int = 1) -> None:
|
|
302
|
-
"""Press mouse down
|
|
303
|
-
|
|
304
|
-
:arg button: mouse button to use, one of ``left``, ``right``, or ``middle``, defaults to ``left``
|
|
305
|
-
:arg clickCount: number of times to click, defaults to 1
|
|
306
|
-
"""
|
|
307
|
-
self._button = button
|
|
308
|
-
await self._client.send(
|
|
309
|
-
'Input.dispatchMouseEvent',
|
|
310
|
-
{
|
|
311
|
-
'type': 'mousePressed',
|
|
312
|
-
'button': self._button,
|
|
313
|
-
'x': self._x,
|
|
314
|
-
'y': self._y,
|
|
315
|
-
'modifiers': self._keyboard._modifiers,
|
|
316
|
-
'clickCount': clickCount,
|
|
317
|
-
},
|
|
318
|
-
)
|
|
319
|
-
|
|
320
|
-
async def up(self, button: str = 'left', clickCount: int = 1) -> None:
|
|
321
|
-
"""Release pressed mouse
|
|
322
|
-
|
|
323
|
-
:arg button: mouse button to use, one of ``left``, ``right``, or ``middle``, defaults to ``left``
|
|
324
|
-
:arg clickCount: number of times to click, defaults to 1
|
|
325
|
-
"""
|
|
326
|
-
self._button = 'none'
|
|
327
|
-
await self._client.send(
|
|
328
|
-
'Input.dispatchMouseEvent',
|
|
329
|
-
{
|
|
330
|
-
'type': 'mouseReleased',
|
|
331
|
-
'button': button,
|
|
332
|
-
'x': self._x,
|
|
333
|
-
'y': self._y,
|
|
334
|
-
'modifiers': self._keyboard._modifiers,
|
|
335
|
-
'clickCount': clickCount,
|
|
336
|
-
},
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
class Touchscreen:
|
|
341
|
-
"""Touchscreen class."""
|
|
342
|
-
|
|
343
|
-
def __init__(self, client: CDPSession, keyboard: Keyboard) -> None:
|
|
344
|
-
"""Make new touchscreen object."""
|
|
345
|
-
self._client = client
|
|
346
|
-
self._keyboard = keyboard
|
|
347
|
-
|
|
348
|
-
async def tap(self, x: float, y: float) -> None:
|
|
349
|
-
"""Tap (``x``, ``y``).
|
|
350
|
-
|
|
351
|
-
Dispatches a ``touchstart`` and ``touchend`` event.
|
|
352
|
-
"""
|
|
353
|
-
# Touches appear to be lost during the first frame after navigation.
|
|
354
|
-
# This waits a frame before sending the tap.
|
|
355
|
-
# see https://crbug.com/613219
|
|
356
|
-
await self._client.send(
|
|
357
|
-
'Runtime.evaluate',
|
|
358
|
-
{
|
|
359
|
-
'expression': 'new Promise(x => requestAnimationFrame(() => requestAnimationFrame(x)))',
|
|
360
|
-
'awaitPromise': True,
|
|
361
|
-
},
|
|
362
|
-
)
|
|
363
|
-
|
|
364
|
-
touchPoints = [{'x': round(x), 'y': round(y)}]
|
|
365
|
-
await self._client.send(
|
|
366
|
-
'Input.dispatchTouchEvent',
|
|
367
|
-
{'type': 'touchStart', 'touchPoints': touchPoints, 'modifiers': self._keyboard._modifiers,},
|
|
368
|
-
)
|
|
369
|
-
await self._client.send(
|
|
370
|
-
'Input.dispatchTouchEvent', {'type': 'touchEnd', 'touchPoints': [], 'modifiers': self._keyboard._modifiers,}
|
|
371
|
-
)
|