PlaywrightCapture 1.24.4__tar.gz → 1.24.5__tar.gz
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.
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/PKG-INFO +1 -1
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/playwrightcapture/capture.py +27 -8
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/pyproject.toml +2 -2
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/LICENSE +0 -0
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/README.md +0 -0
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/playwrightcapture/__init__.py +0 -0
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/playwrightcapture/exceptions.py +0 -0
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/playwrightcapture/helpers.py +0 -0
- {playwrightcapture-1.24.4 → playwrightcapture-1.24.5}/playwrightcapture/py.typed +0 -0
@@ -14,8 +14,9 @@ import time
|
|
14
14
|
|
15
15
|
from base64 import b64decode
|
16
16
|
from io import BytesIO
|
17
|
+
from logging import LoggerAdapter, Logger
|
17
18
|
from tempfile import NamedTemporaryFile
|
18
|
-
from typing import Any, TypedDict, Literal, TYPE_CHECKING
|
19
|
+
from typing import Any, TypedDict, Literal, TYPE_CHECKING, MutableMapping
|
19
20
|
from urllib.parse import urlparse, unquote, urljoin
|
20
21
|
from zipfile import ZipFile
|
21
22
|
|
@@ -79,6 +80,16 @@ class CaptureResponse(TypedDict, total=False):
|
|
79
80
|
potential_favicons: set[bytes] | None
|
80
81
|
|
81
82
|
|
83
|
+
class PlaywrightCaptureLogAdapter(LoggerAdapter): # type: ignore[type-arg]
|
84
|
+
"""
|
85
|
+
Prepend log entry with the UUID of the capture
|
86
|
+
"""
|
87
|
+
def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, MutableMapping[str, Any]]:
|
88
|
+
if self.extra:
|
89
|
+
return '[{}] {}'.format(self.extra['uuid'], msg), kwargs
|
90
|
+
return msg, kwargs
|
91
|
+
|
92
|
+
|
82
93
|
class Capture():
|
83
94
|
|
84
95
|
_browsers: list[BROWSER] = ['chromium', 'firefox', 'webkit']
|
@@ -90,7 +101,8 @@ class Capture():
|
|
90
101
|
|
91
102
|
def __init__(self, browser: BROWSER | None=None, device_name: str | None=None,
|
92
103
|
proxy: str | dict[str, str] | None=None,
|
93
|
-
general_timeout_in_sec: int | None = None, loglevel: str | int='INFO'
|
104
|
+
general_timeout_in_sec: int | None = None, loglevel: str | int='INFO',
|
105
|
+
uuid: str | None=None):
|
94
106
|
"""Captures a page with Playwright.
|
95
107
|
|
96
108
|
:param browser: The browser to use for the capture.
|
@@ -98,9 +110,15 @@ class Capture():
|
|
98
110
|
:param proxy: The external proxy to use for the capture.
|
99
111
|
:param general_timeout_in_sec: The general timeout for the capture, including children.
|
100
112
|
:param loglevel: Python loglevel
|
113
|
+
:param uuid: The UUID of the capture.
|
101
114
|
"""
|
102
|
-
|
103
|
-
|
115
|
+
master_logger = logging.getLogger('playwrightcapture')
|
116
|
+
master_logger.setLevel(loglevel)
|
117
|
+
self.logger: Logger | PlaywrightCaptureLogAdapter
|
118
|
+
if uuid is not None:
|
119
|
+
self.logger = PlaywrightCaptureLogAdapter(master_logger, {'uuid': uuid})
|
120
|
+
else:
|
121
|
+
self.logger = master_logger
|
104
122
|
self.browser_name: BROWSER = browser if browser else 'chromium'
|
105
123
|
|
106
124
|
if general_timeout_in_sec is None:
|
@@ -682,9 +700,6 @@ class Capture():
|
|
682
700
|
except Exception:
|
683
701
|
raise e
|
684
702
|
else:
|
685
|
-
if not self._exception_is_network_error(initial_error):
|
686
|
-
# TODO: Do something?
|
687
|
-
self.logger.warning(f'Unexpected error: {initial_error}')
|
688
703
|
raise initial_error
|
689
704
|
else:
|
690
705
|
await page.bring_to_front()
|
@@ -869,7 +884,11 @@ class Capture():
|
|
869
884
|
'Navigation failed because page was closed!',
|
870
885
|
'Protocol error (Page.bringToFront): Not attached to an active page',
|
871
886
|
'Peer failed to perform TLS handshake: The TLS connection was non-properly terminated.',
|
872
|
-
'
|
887
|
+
'Peer failed to perform TLS handshake: Error sending data: Connection reset by peer',
|
888
|
+
'Peer sent fatal TLS alert: The server name sent was not recognized',
|
889
|
+
'Load cannot follow more than 20 redirections',
|
890
|
+
'Page crashed',
|
891
|
+
'Error receiving data: Connection reset by peer']:
|
873
892
|
# Other errors, let's give it another shot
|
874
893
|
self.logger.info(f'Issue with {url} (retrying): {e.message}')
|
875
894
|
self.should_retry = True
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "PlaywrightCapture"
|
3
|
-
version = "1.24.
|
3
|
+
version = "1.24.5"
|
4
4
|
description = "A simple library to capture websites using playwright"
|
5
5
|
authors = ["Raphaël Vinot <raphael.vinot@circl.lu>"]
|
6
6
|
license = "BSD-3-Clause"
|
@@ -44,7 +44,7 @@ pytest = "^8.1.1"
|
|
44
44
|
mypy = "^1.9.0"
|
45
45
|
types-dateparser = "^1.1.4.20240331"
|
46
46
|
types-requests = "^2.31.0.20240406"
|
47
|
-
types-pytz = "^2024.1.0.
|
47
|
+
types-pytz = "^2024.1.0.20240417"
|
48
48
|
|
49
49
|
|
50
50
|
[build-system]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|