2011-08-01 22:39:16 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""standalone pypi-server, version @VERSION@"""
|
|
|
|
|
|
|
|
sources = """
|
|
|
|
@SOURCES@"""
|
|
|
|
|
2011-11-24 00:54:32 +01:00
|
|
|
import sys, base64, zlib
|
2011-08-01 22:39:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DictImporter(object):
|
2011-11-24 00:54:32 +01:00
|
|
|
sources = None
|
2011-08-01 22:39:16 +02:00
|
|
|
|
|
|
|
def find_module(self, fullname, path=None):
|
|
|
|
if fullname in self.sources:
|
|
|
|
return self
|
|
|
|
if fullname + '.__init__' in self.sources:
|
|
|
|
return self
|
|
|
|
return None
|
|
|
|
|
|
|
|
def load_module(self, fullname):
|
|
|
|
try:
|
|
|
|
s = self.sources[fullname]
|
|
|
|
is_pkg = False
|
|
|
|
except KeyError:
|
|
|
|
s = self.sources[fullname + '.__init__']
|
|
|
|
is_pkg = True
|
|
|
|
|
|
|
|
co = compile(s, fullname, 'exec')
|
2013-02-18 23:23:13 +01:00
|
|
|
try:
|
|
|
|
module = sys.modules.setdefault(fullname, type(sys)(fullname))
|
|
|
|
except TypeError: # jython?
|
|
|
|
import types
|
|
|
|
module = sys.modules.setdefault(fullname, types.ModuleType(fullname))
|
2011-08-01 22:39:16 +02:00
|
|
|
module.__file__ = __file__
|
|
|
|
module.__loader__ = self
|
|
|
|
if is_pkg:
|
|
|
|
module.__path__ = [fullname]
|
|
|
|
|
2011-11-24 00:54:32 +01:00
|
|
|
do_exec(co, module.__dict__)
|
2011-08-01 22:39:16 +02:00
|
|
|
return sys.modules[fullname]
|
|
|
|
|
|
|
|
def get_source(self, name):
|
|
|
|
res = self.sources.get(name)
|
|
|
|
if res is None:
|
|
|
|
res = self.sources.get(name + '.__init__')
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
2011-11-24 00:54:32 +01:00
|
|
|
if sys.version_info >= (3, 0):
|
|
|
|
import pickle
|
|
|
|
exec("def do_exec(co, loc): exec(co, loc)\n")
|
|
|
|
sources = sources.encode("ascii") # ensure bytes
|
|
|
|
d = zlib.decompress(base64.decodebytes(sources))
|
|
|
|
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)), encoding="utf-8")
|
|
|
|
else:
|
|
|
|
import cPickle as pickle
|
|
|
|
exec("def do_exec(co, loc): exec co in loc\n")
|
|
|
|
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
|
|
|
|
|
2011-08-01 22:39:16 +02:00
|
|
|
importer = DictImporter()
|
2011-11-24 00:54:32 +01:00
|
|
|
importer.sources = sources
|
2011-08-01 22:39:16 +02:00
|
|
|
sys.meta_path.append(importer)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2012-10-12 00:15:18 +02:00
|
|
|
from pypiserver import core
|
2013-01-03 22:12:23 +01:00
|
|
|
if sys.version_info >= (2, 6):
|
|
|
|
core.DEFAULT_SERVER = "waitress"
|
|
|
|
else:
|
|
|
|
core.bottle.AutoServer.adapters.remove(core.bottle.WaitressServer)
|
2012-10-12 00:15:18 +02:00
|
|
|
core.main()
|