browserfetch 0.12.0__tar.gz → 0.13.0__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: browserfetch
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: fetch in Python using your browser!
5
5
  Keywords: browser,fetch,python,cookies
6
6
  Requires-Python: >=3.11
@@ -1,4 +1,4 @@
1
- __version__ = '0.12.0'
1
+ __version__ = '0.13.0'
2
2
  __all__ = [
3
3
  'BrowserError',
4
4
  'Response',
@@ -11,7 +11,6 @@ __all__ = [
11
11
  import atexit
12
12
  from asyncio import (
13
13
  AbstractEventLoop,
14
- CancelledError,
15
14
  Event,
16
15
  Task,
17
16
  get_running_loop,
@@ -152,10 +151,21 @@ async def _(request):
152
151
  )
153
152
  logger.info('registering host %s', host)
154
153
 
155
- ws_or_e = hosts[host]
154
+ ws_or_event = hosts[host]
155
+ if not isinstance(ws_or_event, Event):
156
+ await ws.send_bytes(
157
+ _dumps(
158
+ {
159
+ 'action': 'close_ws',
160
+ 'reason': f'a host with the name `{host}` is already registered',
161
+ }
162
+ ).encode()
163
+ )
164
+ await ws.close()
165
+ return ws
166
+
156
167
  hosts[host] = ws
157
- if isinstance(ws_or_e, Event):
158
- ws_or_e.set()
168
+ ws_or_event.set()
159
169
 
160
170
  try:
161
171
  await receive_responses(ws)
@@ -272,7 +282,7 @@ async def fetch(
272
282
  url = urlunparse(
273
283
  parsed_url._replace(
274
284
  query=urlencode(
275
- parse_qsl(parsed_url.query) + [*params.items()]
285
+ [*parse_qsl(parsed_url.query), *params.items()]
276
286
  )
277
287
  )
278
288
  )
@@ -117,6 +117,11 @@
117
117
  var /**@type {Uint8Array | Blob} */ result, j, b;
118
118
  [b, j] = parseData(evt.data);
119
119
  switch (j['action']) {
120
+ case 'close_ws':
121
+ console.debug(`websocket closed. reason: ${j["reason"]}`)
122
+ ws.onclose = null;
123
+ ws.close();
124
+ return;
120
125
  case 'fetch':
121
126
  result = await doFetch(j, b);
122
127
  break;
File without changes
File without changes