cdpbrowser 0.1.0__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.
CdpBrowser.py ADDED
@@ -0,0 +1,19 @@
1
+ """Top-level shim for the bare-name ``Library CdpBrowser`` import.
2
+
3
+ Robot Framework interprets a library name without a dot as a top-level
4
+ module. The actual implementation lives in :mod:`cdpbrowser.library`; this
5
+ module is a re-export that only assists name resolution.
6
+ ``Library cdpbrowser.CdpBrowser`` behaves identically.
7
+
8
+ The adapter is optional packaging-wise: importing this shim without
9
+ robotframework installed fails with install guidance.
10
+ """
11
+
12
+ from cdpbrowser import ROBOT_INSTALL_HINT, _robot_available
13
+
14
+ if not _robot_available():
15
+ raise ImportError(ROBOT_INSTALL_HINT)
16
+
17
+ from cdpbrowser.library import CdpBrowser # noqa: E402
18
+
19
+ __all__ = ["CdpBrowser"]
cdpbrowser/__init__.py ADDED
@@ -0,0 +1,68 @@
1
+ """CdpBrowser — a framework-independent pure-CDP browser automation core.
2
+
3
+ The core (ChromeProcess, CdpConnection, PageSession, and everything under
4
+ ``cdpbrowser.*``) is plain Python + ``websockets`` with **no framework
5
+ dependency** — usable from scripts, pytest, or any tool.
6
+
7
+ The Robot Framework keyword adapter (``cdpbrowser.CdpBrowser``) is optional:
8
+ install it with ``pip install 'cdpbrowser[robot]'``.
9
+ """
10
+
11
+ from importlib.util import find_spec as _find_spec
12
+
13
+ __version__ = "0.1.0"
14
+
15
+ #: Guidance shown when the Robot adapter is accessed without robotframework.
16
+ ROBOT_INSTALL_HINT = (
17
+ "cdpbrowser.CdpBrowser is the optional Robot Framework adapter — "
18
+ "install robotframework with: pip install 'cdpbrowser[robot]'. "
19
+ "The framework-free core (PageSession & friends) needs no extras."
20
+ )
21
+
22
+
23
+ def _robot_available() -> bool:
24
+ """Whether ``robotframework`` is importable (tolerates broken installs)."""
25
+ try:
26
+ return _find_spec("robot") is not None
27
+ except Exception: # noqa: BLE001 — a raising finder means "unavailable"
28
+ return False
29
+
30
+
31
+ # --- Core exports: eager, framework-free --------------------------------
32
+ from .cdp.chrome import ChromeProcess, find_chrome # noqa: E402
33
+ from .cdp.transport import CdpConnection # noqa: E402
34
+ from .page import PageSession # noqa: E402
35
+
36
+
37
+ # --- Robot adapter: lazy, guarded (PEP 562) ------------------------------
38
+ def __getattr__(name):
39
+ if name == "CdpBrowser":
40
+ if not _robot_available():
41
+ raise ImportError(ROBOT_INSTALL_HINT)
42
+ try:
43
+ from .library import CdpBrowser
44
+ except ImportError as exc:
45
+ raise ImportError(ROBOT_INSTALL_HINT) from exc
46
+ return CdpBrowser
47
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
48
+
49
+
50
+ def __dir__():
51
+ return [
52
+ "__version__",
53
+ "ChromeProcess",
54
+ "find_chrome",
55
+ "CdpConnection",
56
+ "PageSession",
57
+ "CdpBrowser",
58
+ ]
59
+
60
+
61
+ __all__ = [
62
+ "__version__",
63
+ "ChromeProcess",
64
+ "find_chrome",
65
+ "CdpConnection",
66
+ "PageSession",
67
+ "CdpBrowser",
68
+ ]