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.
- {pytwojs-1.1.0 → pytwojs-1.2.0}/PKG-INFO +1 -1
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs/interpreter.py +31 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs.egg-info/PKG-INFO +1 -1
- {pytwojs-1.1.0 → pytwojs-1.2.0}/setup.py +1 -1
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs/__init__.py +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs/_program.py +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs/exceptions.py +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs/utils.py +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs.egg-info/SOURCES.txt +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs.egg-info/dependency_links.txt +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs.egg-info/requires.txt +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/pytwojs.egg-info/top_level.txt +0 -0
- {pytwojs-1.1.0 → pytwojs-1.2.0}/setup.cfg +0 -0
|
@@ -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
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|