runner-runtime 1.0.135 → 1.0.137
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.
|
Binary file
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import sys
|
|
3
|
-
import urllib2
|
|
4
3
|
import tempfile
|
|
5
4
|
import ssl
|
|
6
5
|
import os
|
|
7
6
|
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
# 1. 兼容性导入:处理 urllib2 (Py2) 和 urllib.request (Py3)
|
|
8
|
+
try:
|
|
9
|
+
import urllib2 as request_module
|
|
10
|
+
except ImportError:
|
|
11
|
+
import urllib.request as request_module
|
|
12
|
+
|
|
13
|
+
# 2. 兼容性编码处理 (仅在 Py2 下执行)
|
|
14
|
+
if sys.version_info[0] < 3:
|
|
15
|
+
reload(sys)
|
|
16
|
+
sys.setdefaultencoding('utf-8')
|
|
11
17
|
|
|
12
18
|
def run_remote_python():
|
|
13
19
|
if len(sys.argv) < 2:
|
|
@@ -18,31 +24,42 @@ def run_remote_python():
|
|
|
18
24
|
tmp_file_path = None
|
|
19
25
|
|
|
20
26
|
try:
|
|
21
|
-
#
|
|
27
|
+
# 3. 兼容性下载逻辑
|
|
22
28
|
context = ssl._create_unverified_context()
|
|
23
|
-
response =
|
|
29
|
+
response = request_module.urlopen(url, context=context)
|
|
24
30
|
content = response.read()
|
|
25
31
|
|
|
26
|
-
#
|
|
32
|
+
# 4. 创建临时文件
|
|
27
33
|
fd, tmp_file_path = tempfile.mkstemp(suffix=".py")
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
|
|
35
|
+
# Py3 需要以二进制写入,或者指定 encoding
|
|
36
|
+
if sys.version_info[0] >= 3:
|
|
37
|
+
with os.fdopen(fd, 'wb') as tmp:
|
|
38
|
+
tmp.write(content)
|
|
39
|
+
else:
|
|
40
|
+
with os.fdopen(fd, 'w') as tmp:
|
|
41
|
+
tmp.write(content)
|
|
30
42
|
|
|
31
|
-
#
|
|
32
|
-
# 将 sys.argv 彻底替换,不留调度器的痕迹
|
|
43
|
+
# 5. 模拟环境:替换 sys.argv
|
|
33
44
|
sys.argv = [url] + extra_args
|
|
34
45
|
|
|
35
46
|
exec_globals = {
|
|
36
47
|
"__name__": "__main__",
|
|
37
|
-
"__file__": tmp_file_path
|
|
48
|
+
"__file__": tmp_file_path,
|
|
49
|
+
"__builtins__": __builtins__
|
|
38
50
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
|
|
52
|
+
# 兼容性执行逻辑
|
|
53
|
+
if sys.version_info[0] < 3:
|
|
54
|
+
# Python 2 方案
|
|
55
|
+
execfile(tmp_file_path, exec_globals)
|
|
56
|
+
else:
|
|
57
|
+
# Python 3 方案
|
|
58
|
+
with open(tmp_file_path, 'rb') as f:
|
|
59
|
+
code = compile(f.read(), tmp_file_path, 'exec')
|
|
60
|
+
exec(code, exec_globals)
|
|
43
61
|
|
|
44
62
|
except Exception as e:
|
|
45
|
-
# 错误信息输出到 stderr,不会被 stdout 捕获
|
|
46
63
|
sys.stderr.write("[Launcher Error] " + str(e) + "\n")
|
|
47
64
|
finally:
|
|
48
65
|
if tmp_file_path and os.path.exists(tmp_file_path):
|