pytwojs 1.1.0__tar.gz → 1.2.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.1
2
2
  Name: pytwojs
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A high-performance Python library that relies on nodejs to execute JavaScript
5
5
  Author: Samwe
6
6
  Author-email: 1281722462@qq.com
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
  __package__ = "pytwojs"
3
3
 
4
4
  import json
5
+ import re
5
6
  import subprocess
6
7
  import typing
7
8
  import threading
@@ -52,7 +53,30 @@ class NodeInterpreter:
52
53
  self._flush()
53
54
  self._write(EXEC_END_FLAGS)
54
55
  self._flush()
56
+ _out = b''
57
+ is_err = False
55
58
  while out := self._readline():
59
+ if is_err:
60
+ _out += out
61
+ try:
62
+ _match = self._extract_json(_out)
63
+ if not _match:
64
+ continue
65
+
66
+ out_obj = json.loads(_match.group(), strict=False)
67
+ except json.JSONDecodeError:
68
+ continue
69
+ else:
70
+ try:
71
+ raise JSException(out_obj['toString'])
72
+ finally:
73
+ self.close()
74
+
75
+ if out.strip()[:8] == b"Uncaught":
76
+ _out += out.strip()[8:]
77
+ is_err = True
78
+ continue
79
+
56
80
  try:
57
81
  out_obj = json.loads(out)
58
82
  if isinstance(out_obj, dict):
@@ -105,6 +129,10 @@ class NodeInterpreter:
105
129
  def close(self) -> None:
106
130
  self._finalizer()
107
131
 
132
+ @staticmethod
133
+ def _extract_json(out: bytes):
134
+ return re.search(rb'\{.*\}', out, re.S)
135
+
108
136
  def _write(self, code: bytes):
109
137
  self._node.stdin.write(code)
110
138
 
@@ -114,6 +142,9 @@ class NodeInterpreter:
114
142
  def _readline(self):
115
143
  return self._node.stdout.readline()
116
144
 
145
+ def _communicate(self):
146
+ return self._node.communicate()
147
+
117
148
  def __enter__(self) -> NodeInterpreter:
118
149
  return self
119
150
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytwojs
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: A high-performance Python library that relies on nodejs to execute JavaScript
5
5
  Author: Samwe
6
6
  Author-email: 1281722462@qq.com
@@ -9,7 +9,7 @@ DESCRIPTION = 'A high-performance Python library that relies on nodejs to execut
9
9
 
10
10
  setup(
11
11
  name="pytwojs",
12
- version="1.1.0",
12
+ version="1.2.0",
13
13
  packages=find_packages(),
14
14
  author=AUTHOR,
15
15
  author_email=EMAIL,
File without changes
File without changes
File without changes
File without changes
File without changes