-
Notifications
You must be signed in to change notification settings - Fork 35
/
boot_plugin.py
52 lines (38 loc) · 1.21 KB
/
boot_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import re
import sys
cookie_re = re.compile(rb"coding[:=]\s*([-\w.]+)")
if sys.version_info[0] == 2:
default_encoding = "ascii"
else:
default_encoding = "utf-8"
def guess_encoding(fp):
for _i in range(2):
ln = fp.readline()
m = cookie_re.search(ln)
if m is not None:
return m.group(1).decode("ascii")
return default_encoding
def _run():
global __file__
import os
import site # noqa: F401
sys.frozen = "macosx_plugin"
base = os.environ["RESOURCEPATH"]
if "ARGVZERO" in os.environ:
argv0 = os.path.basename(os.environ["ARGVZERO"])
else:
argv0 = None
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT) # noqa: F821
__file__ = path = os.path.join(base, script)
if sys.version_info[0] == 2:
with open(path, "rU") as fp:
source = fp.read() + "\n"
else:
with open(path, "rb") as fp:
encoding = guess_encoding(fp)
with open(path, "r", encoding=encoding) as fp:
source = fp.read() + "\n"
BOM = b"\xef\xbb\xbf".decode("utf-8")
if source.startswith(BOM):
source = source[1:]
exec(compile(source, path, "exec"), globals(), globals())