PlaywrightCapture 1.24.4__py3-none-any.whl → 1.24.5__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.
@@ -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
- self.logger = logging.getLogger('playwrightcapture')
103
- self.logger.setLevel(loglevel)
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
- 'Load cannot follow more than 20 redirections']:
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
  Metadata-Version: 2.1
2
2
  Name: PlaywrightCapture
3
- Version: 1.24.4
3
+ Version: 1.24.5
4
4
  Summary: A simple library to capture websites using playwright
5
5
  Home-page: https://github.com/Lookyloo/PlaywrightCapture
6
6
  License: BSD-3-Clause
@@ -1,9 +1,9 @@
1
1
  playwrightcapture/__init__.py,sha256=F90Y8wYS13tDjgsfjuFrCfmzQfdnH44G-ovuilJfLEE,511
2
- playwrightcapture/capture.py,sha256=0QTHf1zgR9jI112Vd-WVezLt6dNocl8nkvBzMAQFVZM,62432
2
+ playwrightcapture/capture.py,sha256=-30zUyPeS8VPt-8MZhkYmFiJEvq9LwAZFp0ChhWeRsY,63307
3
3
  playwrightcapture/exceptions.py,sha256=LhGJQCGHzEu7Sx2Dfl28OFeDg1OmrwufFjAWXlxQnEA,366
4
4
  playwrightcapture/helpers.py,sha256=SXQLEuxMs8-bcWykMiUVosHzzxBKuS-QC0gBV3OmKmo,1764
5
5
  playwrightcapture/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- playwrightcapture-1.24.4.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
7
- playwrightcapture-1.24.4.dist-info/METADATA,sha256=NXKwII6UDKaLf-igQQ4RAInjfzZBiXVn7qhdcTe687Y,3077
8
- playwrightcapture-1.24.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
- playwrightcapture-1.24.4.dist-info/RECORD,,
6
+ playwrightcapture-1.24.5.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
7
+ playwrightcapture-1.24.5.dist-info/METADATA,sha256=fT8WNXOeQ5hQVkN7cQhd29L1S3CwShSvd5jpq53orYE,3077
8
+ playwrightcapture-1.24.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
9
+ playwrightcapture-1.24.5.dist-info/RECORD,,