browserfetch 0.8.0__tar.gz → 0.8.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.1
2
2
  Name: browserfetch
3
- Version: 0.8.0
3
+ Version: 0.8.1
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.0'
1
+ __version__ = '0.8.1'
2
2
 
3
3
  import atexit
4
4
  from asyncio import (
@@ -4,10 +4,11 @@
4
4
  // @match https://example.com/
5
5
  // @grant GM_registerMenuCommand
6
6
  // ==/UserScript==
7
+ // @ts-check
7
8
  (() => {
8
9
  /**
9
- * @param {Blob} body
10
- * @param {j} Object
10
+ * @param {Uint8Array | null} body
11
+ * @param {Object} req
11
12
  * @returns {Promise<Blob>}
12
13
  */
13
14
  async function doFetch(req, body) {
@@ -47,16 +48,16 @@
47
48
 
48
49
  /**
49
50
  *
50
- * @param {String} s
51
+ * @param {Object} req
51
52
  * @returns {Promise<Uint8Array>}
52
53
  */
53
54
  async function doEval(req) {
54
55
  var evalled, resp;
55
56
  try {
56
57
  evalled = eval(req['string']);
57
- resp = {'result': evalled, 'event_id': req['event_id']};
58
+ resp = { 'result': evalled, 'event_id': req['event_id'] };
58
59
  } catch (err) {
59
- resp = {'result': err.toString(), 'event_id': req['event_id']};
60
+ resp = { 'result': err.toString(), 'event_id': req['event_id'] };
60
61
  }
61
62
  return new TextEncoder().encode(JSON.stringify(resp));
62
63
  }
@@ -64,7 +65,7 @@
64
65
  /**
65
66
  *
66
67
  * @param {ArrayBuffer} d
67
- * @returns {Array.<{binaryPart: Uint8Array, jsonPart: Object}>}
68
+ * @returns {[Uint8Array | null, Object]}
68
69
  */
69
70
  function parseData(d) {
70
71
  var blob, jArray;
@@ -96,7 +97,7 @@
96
97
  };
97
98
 
98
99
  ws.onmessage = async (evt) => {
99
- var result, j, b;
100
+ var /**@type {Uint8Array | Blob} */ result, j, b;
100
101
  [b, j] = parseData(evt.data);
101
102
  switch (j['action']) {
102
103
  case 'fetch':
@@ -104,12 +105,21 @@
104
105
  break;
105
106
  case 'eval':
106
107
  result = await doEval(j);
108
+ break;
109
+ default:
110
+ result = new TextEncoder().encode(JSON.stringify({
111
+ 'event_id': j['event_id'],
112
+ 'error': `Action ${j['action']} is not defined.`
113
+ }));
114
+ break;
107
115
  }
108
116
  ws.send(result);
109
117
  }
110
118
  };
111
119
 
120
+ // @ts-ignore
112
121
  if (window.GM_registerMenuCommand) {
122
+ // @ts-ignore
113
123
  GM_registerMenuCommand(
114
124
  'connect to browserfetch',
115
125
  connect
File without changes
File without changes