forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IronyImporter.py
57 lines (45 loc) · 1.44 KB
/
IronyImporter.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
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月28日
@author: Irony."[讽刺]
@site: http://alyl.vip, http://orzorz.vip, https://coding.net/u/892768447, https://github.com/892768447
@email: [email protected]
@file: IronyImporter
@description:
'''
import base64
import os
import sys
from types import ModuleType
import xxtea # @UnresolvedImport
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: [email protected]"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
KEY = base64.b85decode("HF5^hbNbOVOKM=(SB`7h")
class IronyImporter:
@classmethod
def find_module(cls, name, path=None):
name = name + ".irony"
if not os.path.isfile(name):
return None
return cls
@classmethod
def load_module(cls, name):
if name in sys.modules:
return sys.modules[name]
mod = ModuleType(name)
mod.__loader__ = cls
mod.__name__ = name
mod.__file__ = name + ".irony"
try:
exec(xxtea.decrypt(open(mod.__file__, "rb").read(), KEY), mod.__dict__)
except Exception as e:
print(e)
return None
sys.modules[name] = mod
return mod
@classmethod
def module_repr(cls, module):
return "<module {!r} from ({!r})>".format(module.__name__, module.__file__)
sys.meta_path.insert(0, IronyImporter)