PlaywrightCapture 1.41.1__tar.gz → 1.41.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PlaywrightCapture
3
- Version: 1.41.1
3
+ Version: 1.41.2
4
4
  Summary: A simple library to capture websites using playwright
5
5
  License-Expression: BSD-3-Clause
6
6
  License-File: LICENSE
@@ -1397,8 +1397,8 @@ class Capture():
1397
1397
  await route.continue_()
1398
1398
  else:
1399
1399
  # other URLs
1400
- not_local, message = self.__check_local_url(request.url)
1401
- if not_local:
1400
+ public, message = self.__check_local_url(request.url)
1401
+ if public:
1402
1402
  await route.continue_()
1403
1403
  else:
1404
1404
  await route.fulfill(status=404, content_type="text/plain", body=message)
@@ -2294,6 +2294,15 @@ class Capture():
2294
2294
  In the meantime, we try to get all the potential ones in this method.
2295
2295
  Method inspired by https://github.com/ail-project/ail-framework/blob/master/bin/lib/crawlers.py
2296
2296
  """
2297
+ async def __check_local_middleware(req: aiohttp.ClientRequest, handler: aiohttp.ClientHandlerType) -> aiohttp.ClientResponse:
2298
+ if self.only_global_lookup:
2299
+ public, message = self.__check_local_url(str(req.url))
2300
+ if public is False:
2301
+ # got a local URL
2302
+ self.logger.warning(f'Attempted to get a local favicon (in redirect): {message}')
2303
+ raise aiohttp.ClientError(f'Attempted to get a local favicon (in redirect): {message}')
2304
+ return await handler(req)
2305
+
2297
2306
  connector = None
2298
2307
  if self.proxy:
2299
2308
  # NOTE 2024-05-17: switch to async to fetch, the lib uses socks5h by default
@@ -2319,8 +2328,8 @@ class Capture():
2319
2328
  continue
2320
2329
 
2321
2330
  if self.only_global_lookup:
2322
- not_local, message = self.__check_local_url(url_to_fetch)
2323
- if not_local is False:
2331
+ public, message = self.__check_local_url(url_to_fetch)
2332
+ if public is False:
2324
2333
  # got a local URL
2325
2334
  self.logger.warning(f'Attempted to get a local favicon: {message}')
2326
2335
  continue
@@ -2328,7 +2337,7 @@ class Capture():
2328
2337
  if url_to_fetch in self._requests:
2329
2338
  favicon = self._requests[url_to_fetch]
2330
2339
  if not favicon:
2331
- async with session.get(url_to_fetch, ssl=False) as favicon_response:
2340
+ async with session.get(url_to_fetch, ssl=False, middlewares=[__check_local_middleware]) as favicon_response:
2332
2341
  favicon_response.raise_for_status()
2333
2342
  favicon = await favicon_response.read()
2334
2343
  if favicon:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PlaywrightCapture"
3
- version = "1.41.1"
3
+ version = "1.41.2"
4
4
  description = "A simple library to capture websites using playwright"
5
5
  authors = [
6
6
  {name="Raphaël Vinot", email= "raphael.vinot@circl.lu"}