browserfetch 0.16.0__tar.gz → 0.16.1__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.3
2
2
  Name: browserfetch
3
- Version: 0.16.0
3
+ Version: 0.16.1
4
4
  Summary: fetch in Python using your browser!
5
5
  Keywords: browser,fetch,python,cookies
6
6
  License: GNU General Public License v3 (GPLv3)
@@ -1,4 +1,4 @@
1
- __version__ = '0.16.0'
1
+ __version__ = '0.16.1'
2
2
  __all__ = [
3
3
  'BrowserError',
4
4
  'Response',
@@ -146,32 +146,36 @@ async def _(request):
146
146
  )
147
147
  logger.info('registering host %s', host)
148
148
 
149
- ws_or_event = hosts[host]
150
- if not isinstance(ws_or_event, Event):
151
- await ws.send_bytes(
152
- _dumps(
153
- {
154
- 'action': 'close_ws',
155
- 'reason': f'a host with the name `{host}` is already registered',
156
- }
157
- ).encode()
158
- )
159
- await ws.close()
160
- return ws
161
-
149
+ prev_ws_or_event = hosts[host]
162
150
  hosts[host] = ws
163
- ws_or_event.set()
151
+ if isinstance(prev_ws_or_event, Event):
152
+ prev_ws_or_event.set()
153
+ else:
154
+ try:
155
+ await prev_ws_or_event.send_bytes(
156
+ _dumps(
157
+ {
158
+ 'action': 'close_ws',
159
+ 'reason': f'a new host with the name `{host}` replaced the old one',
160
+ }
161
+ ).encode()
162
+ )
163
+ await prev_ws_or_event.close()
164
+ except Exception as e: # noqa: BLE001
165
+ logger.warning('closing the old websocket failed: %r', e)
164
166
 
165
167
  try:
166
168
  await receive_responses(ws)
167
169
  except TypeError:
168
170
  logger.info('WebSocket was closed by browser')
169
- hosts[host] = Event()
171
+ finally:
172
+ if hosts.get(host) is ws:
173
+ hosts[host] = Event()
170
174
  return ws
171
175
 
172
176
 
173
177
  @routes.get('/relay')
174
- async def _(request: Request) -> WebSocketResponse:
178
+ async def relay(request: Request) -> WebSocketResponse:
175
179
  ws = WebSocketResponse()
176
180
  await ws.prepare(request)
177
181
 
@@ -241,7 +245,7 @@ async def evaluate(
241
245
  /,
242
246
  *,
243
247
  host: str,
244
- timeout: int | float = 95,
248
+ timeout: float = 95,
245
249
  arg: _Any = None,
246
250
  ):
247
251
  """Evaluate string in browser context and return JSON.stringify(result)."""
@@ -259,7 +263,7 @@ async def fetch(
259
263
  params: dict | None = None,
260
264
  data: _Any = None,
261
265
  form: dict | None = None,
262
- timeout: int | float = 95,
266
+ timeout: float = 95,
263
267
  headers: dict | None = None,
264
268
  host: str | None = None,
265
269
  options: dict | None = None,
@@ -347,7 +351,7 @@ async def start_server(*, host=_host, port=_port):
347
351
  try:
348
352
  await relay_client(host, port) # blocks
349
353
  finally:
350
- logger.error('relay failed: %s', e)
354
+ logger.debug('relay connection failed or was shutdown')
351
355
  return
352
356
 
353
357
  _server = True
@@ -11,7 +11,7 @@ classifiers = [
11
11
  ]
12
12
  requires-python = ">=3.13"
13
13
  dependencies = ["aiohttp", "pyperclip", "cyclopts"]
14
- version = "0.16.0"
14
+ version = "0.16.1"
15
15
 
16
16
  [[authors]]
17
17
  name = "5j9"
File without changes