| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
sources = """ |
| 23 |
@SOURCES@""" |
| 24 |
|
| 25 |
import sys |
| 26 |
import base64 |
| 27 |
import zlib |
| 28 |
|
| 29 |
class DictImporter(object): |
| 30 |
def __init__(self, sources): |
| 31 |
self.sources = sources |
| 32 |
|
| 33 |
def find_module(self, fullname, path=None): |
| 34 |
if fullname == "argparse" and sys.version_info >= (2,7): |
| 35 |
|
| 36 |
|
| 37 |
return None |
| 38 |
if fullname in self.sources: |
| 39 |
return self |
| 40 |
if fullname + '.__init__' in self.sources: |
| 41 |
return self |
| 42 |
return None |
| 43 |
|
| 44 |
def load_module(self, fullname): |
| 45 |
|
| 46 |
from types import ModuleType |
| 47 |
try: |
| 48 |
s = self.sources[fullname] |
| 49 |
is_pkg = False |
| 50 |
except KeyError: |
| 51 |
s = self.sources[fullname + '.__init__'] |
| 52 |
is_pkg = True |
| 53 |
|
| 54 |
co = compile(s, fullname, 'exec') |
| 55 |
module = sys.modules.setdefault(fullname, ModuleType(fullname)) |
| 56 |
module.__file__ = "%s/%s" % (__file__, fullname) |
| 57 |
module.__loader__ = self |
| 58 |
if is_pkg: |
| 59 |
module.__path__ = [fullname] |
| 60 |
|
| 61 |
do_exec(co, module.__dict__) |
| 62 |
return sys.modules[fullname] |
| 63 |
|
| 64 |
def get_source(self, name): |
| 65 |
res = self.sources.get(name) |
| 66 |
if res is None: |
| 67 |
res = self.sources.get(name + '.__init__') |
| 68 |
return res |
| 69 |
|
| 70 |
if __name__ == "__main__": |
| 71 |
try: |
| 72 |
import pkg_resources |
| 73 |
except ImportError: |
| 74 |
sys.stderr.write("ERROR: setuptools not installed\n") |
| 75 |
sys.exit(2) |
| 76 |
if sys.version_info >= (3, 0): |
| 77 |
exec("def do_exec(co, loc): exec(co, loc)\n") |
| 78 |
import pickle |
| 79 |
sources = sources.encode("ascii") |
| 80 |
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) |
| 81 |
else: |
| 82 |
import cPickle as pickle |
| 83 |
exec("def do_exec(co, loc): exec co in loc\n") |
| 84 |
sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) |
| 85 |
|
| 86 |
importer = DictImporter(sources) |
| 87 |
sys.meta_path.insert(0, importer) |
| 88 |
entry = "@ENTRY@" |
| 89 |
do_exec(entry, locals()) |