Пример #1
0
 def load_module(self, fullname):
     if sys.modules.has_key(fullname):
         mod = sys.modules[fullname]
         if _memimporter.get_verbose_flag():
             sys.stderr.write("import %s # previously loaded from zipfile %s\n" % (fullname, self.archive))
         return mod
     _memimporter.set_find_proc(self.locate_dll_image)
     try:
         return zipimport.zipimporter.load_module(self, fullname)
     except zipimport.ZipImportError:
         pass
     initname = "init" + fullname.split(".")[-1] # name of initfunction
     filename = fullname.replace(".", "\\")
     if filename in ("pywintypes", "pythoncom"):
         filename = filename + "%d%d" % sys.version_info[:2]
         suffixes = ('.dll',)
     else:
         suffixes = self._suffixes
     for s in suffixes:
         path = filename + s
         if path in self._files:
             if _memimporter.get_verbose_flag():
                 sys.stderr.write("# found %s in zipfile %s\n" % (path, self.archive))
             code = self.get_data(path)
             mod = _memimporter.import_module(code, initname, fullname, path)
             mod.__file__ = "%s\\%s" % (self.archive, path)
             mod.__loader__ = self
             if _memimporter.get_verbose_flag():
                 sys.stderr.write("import %s # loaded from zipfile %s\n" % (fullname, mod.__file__))
             return mod
     raise zipimport.ZipImportError, "can't find module %s" % fullname
Пример #2
0
def __bootstrap__():
   global __bootstrap__, __loader__, __file__
   import _memimporter, sys
   _memimporter.set_find_proc(lambda x: __loader__.get_data(r'%s%s' % (__loader__.prefix, x)))
   __file__ = r'%s%s.pyd' % (__loader__.prefix, __name__.split('.')[-1])
   mod = _memimporter.import_module(__loader__.get_data(__file__), 'init'+__name__.split('.')[-1], __name__, __file__)
   mod.__file__ = __file__
   mod.__loader__ = __loader__
   sys.modules[__name__] = mod
   del __bootstrap__, __loader__, __file__, _memimporter, sys