browserfetch 0.8.1__tar.gz → 0.9.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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: browserfetch
3
- Version: 0.8.1
3
+ Version: 0.9.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.8.1'
1
+ __version__ = '0.9.0'
2
2
 
3
3
  import atexit
4
4
  from asyncio import (
@@ -137,6 +137,7 @@ async def _(request):
137
137
  except TypeError:
138
138
  logger.info('host WebSocket was closed')
139
139
  hosts[host] = Event()
140
+ return ws
140
141
 
141
142
 
142
143
  @routes.get('/relay')
@@ -202,11 +203,11 @@ async def evaluate(
202
203
  async def fetch(
203
204
  url: str,
204
205
  *,
205
- params: dict = None,
206
- body: bytes = None,
206
+ params: dict | None = None,
207
+ body: bytes | None = None,
207
208
  timeout: int | float = 95,
208
- options: dict = None,
209
- host=None,
209
+ options: dict | None = None,
210
+ host: str | None = None,
210
211
  ) -> Response:
211
212
  """Fetch using browser fetch API available on host.
212
213
 
@@ -242,9 +243,9 @@ async def fetch(
242
243
  async def get(
243
244
  url: str,
244
245
  *,
245
- params: dict = None,
246
- options: dict = None,
247
- host: str = None,
246
+ params: dict | None = None,
247
+ options: dict | None = None,
248
+ host: str | None = None,
248
249
  timeout: int | float = 95,
249
250
  ) -> Response:
250
251
  if options is None:
@@ -259,28 +260,31 @@ async def get(
259
260
  async def post(
260
261
  url: str,
261
262
  *,
262
- params: dict = None,
263
- body: bytes = None,
264
- data: dict = None,
265
- json=None,
263
+ params: dict | None = None,
264
+ data: bytes | dict | str | None = None,
265
+ form: dict | None = None,
266
266
  timeout: int | float = 95,
267
- options: dict = None,
268
- host: str = None,
267
+ options: dict | None = None,
268
+ host: str | None = None,
269
269
  ) -> Response:
270
270
  if options is None:
271
271
  options: dict[str, Any] = {'method': 'POST'}
272
272
  else:
273
273
  options['method'] = 'POST'
274
274
 
275
- if json is not None:
276
- assert body is None
277
- body = dumps(json).encode()
278
- headers = options.setdefault('headers', {})
279
- headers['Content-Type'] = 'application/json'
280
-
281
275
  if data is not None:
282
- assert body is None
283
- body = urlencode(data).encode()
276
+ if isinstance(data, str):
277
+ body = data.encode()
278
+ elif isinstance(data, bytes):
279
+ body = data
280
+ else:
281
+ body = dumps(data).encode()
282
+ headers = options.setdefault('headers', {})
283
+ headers['Content-Type'] = 'application/json'
284
+
285
+ if form is not None:
286
+ assert data is None
287
+ body = urlencode(form).encode()
284
288
  headers = options.setdefault('headers', {})
285
289
  headers['Content-Type'] = 'application/x-www-form-urlencoded'
286
290
 
@@ -55,6 +55,17 @@
55
55
  var evalled, resp;
56
56
  try {
57
57
  evalled = eval(req['string']);
58
+ switch (evalled.constructor.name) {
59
+ case 'AsyncFunction':
60
+ evalled = await evalled;
61
+ break;
62
+ case 'Promise':
63
+ evalled = await evalled;
64
+ break;
65
+ case 'Function':
66
+ evalled = evalled();
67
+ break;
68
+ }
58
69
  resp = { 'result': evalled, 'event_id': req['event_id'] };
59
70
  } catch (err) {
60
71
  resp = { 'result': err.toString(), 'event_id': req['event_id'] };
@@ -92,7 +103,7 @@
92
103
  }
93
104
 
94
105
  ws.onclose = () => {
95
- console.error('browserfetch: WebSocket was closed; will retry in 5 seconds');
106
+ console.error('WebSocket was closed; will retry in 5 seconds');
96
107
  setTimeout(connect, 5000);
97
108
  };
98
109
 
@@ -35,13 +35,22 @@ line-length = 79
35
35
  format.quote-style = 'single'
36
36
  lint.isort.combine-as-imports = true
37
37
  lint.extend-select = [
38
+ 'FA', # flake8-future-annotations
38
39
  'I', # isort
39
40
  'UP', # pyupgrade
40
41
  ]
41
42
  lint.ignore = [
42
- 'UP027', # list comprehensions are faster than generator expressions
43
43
  'E721', # Do not compare types, use `isinstance()`
44
44
  ]
45
45
 
46
46
  [tool.pytest.ini_options]
47
47
  addopts = '--quiet --tb=short'
48
+
49
+ [tool.pyright]
50
+ typeCheckingMode = 'standard'
51
+ reportDeprecated = "warning"
52
+ reportPropertyTypeMismatch = "warning"
53
+ reportUnnecessaryCast = "warning"
54
+ reportUnnecessaryContains = "warning"
55
+ reportUnnecessaryIsInstance = "warning"
56
+ reportUnnecessaryTypeIgnoreComment = true
File without changes
File without changes