def _getCOMModuleForLocation(self, componentFile): if not self._registred_pylib_paths: self._registred_pylib_paths = 1 try: self._setupPythonPaths() except: import traceback traceback.print_exc() fqn = componentFile.path if fqn[-4:] in (".pyc", ".pyo"): fqn = fqn[:-1] if not fqn.endswith(".py"): raise xpcom.ServerException(nsError.NS_ERROR_INVALID_ARG) mod = self.com_modules.get(fqn) if mod is not None: return mod import ihooks, sys base_name = os.path.splitext(os.path.basename(fqn))[0] loader = ihooks.ModuleLoader() module_name_in_sys = "component:%s" % (base_name, ) stuff = loader.find_module(base_name, [componentFile.parent.path]) assert stuff is not None, "Couldn't find the module '%s'" % ( base_name, ) py_mod = loader.load_module(module_name_in_sys, stuff) # Make and remember the COM module. comps = FindCOMComponents(py_mod) mod = self.moduleFactory(comps) self.com_modules[fqn] = mod return mod
def _getCOMModuleForLocation(self, componentFile): fqn = componentFile.path mod = self.com_modules.get(fqn) if mod is not None: return mod import ihooks, sys base_name = os.path.splitext(os.path.basename(fqn))[0] loader = ihooks.ModuleLoader() module_name_in_sys = "component:%s" % (base_name,) stuff = loader.find_module(base_name, [componentFile.parent.path]) assert stuff is not None, "Couldnt find the module '%s'" % (base_name,) py_mod = loader.load_module( module_name_in_sys, stuff ) # Make and remember the COM module. comps = FindCOMComponents(py_mod) mod = self.moduleFactory(comps) self.com_modules[fqn] = mod return mod
class ModuleObject(CallableObject, BaseObject): implemented_type = 'module' insts_handlers = deepcopy(CallableObject.insts_handlers) il = ihooks.ModuleLoader() def __init__(self, module=None, name=None, path=None): CallableObject.__init__(self) self.implemented_values = [] self.linked_may_names = [] self.linked_must_names = [] if name: self.create_from_const(module.top.codeobj) self.names = {name: path} self.last_name = name self.module = module self.attrs = {} else: self.names = {} self.module = None self.attrs = {} def __deepcopy__(self, memo): res = self.__class__() res.module = self.module res.names = copy(self.names) res.last_name = self.last_name res.attrs = copy(self.attrs) return res def _set_attrs(self): cur_name = self.last_name try: smt = self.module.cfg[cur_name].bbs['exit'].states['normal'].smtbl self.attrs.clear() for name, v in smt.globals.items(): self.attrs[name] = v except KeyError, msg: print "Warning: %r" % sys.exc_info()[1] self.attrs.clear()
def _getCOMModuleForLocation(self, componentFile): fqn = componentFile.path if not fqn.endswith(".py"): raise xpcom.ServerException(nsError.NS_ERROR_INVALID_ARG) mod = self.com_modules.get(fqn) if mod is not None: return mod import ihooks, sys base_name = os.path.splitext(os.path.basename(fqn))[0] loader = ihooks.ModuleLoader() module_name_in_sys = "component:%s" % (base_name, ) stuff = loader.find_module(base_name, [componentFile.parent.path]) assert stuff is not None, "Couldn't find the module '%s'" % ( base_name, ) py_mod = loader.load_module(module_name_in_sys, stuff) # Make and remember the COM module. comps = FindCOMComponents(py_mod) mod = self.moduleFactory(comps) self.com_modules[fqn] = mod return mod
class TypeModule(TypeCallable, TypeBaseObject): implemented_types = ('module', ) insts_handler = deepcopy(TypeCallable.insts_handler) insts_handler.update(TypeBaseObject.insts_handler) implemented_insts = insts_handler.stored_insts # print implemented_insts import ihooks il = ihooks.ModuleLoader() # if getglobal('include_path'): # il.default_path().append(include_path) def __init__(self, module=None, name=None, path=None): TypeCallable.__init__(self) if name: self.create_from_const(module.top.codeobj) self.names = {name: path} self.last_name = name self.module = module self.attrs = {} else: self.names = {} self.module = None self.attrs = {} def __deepcopy__(self, memo): res = self.__class__() res.module = self.module res.names = copy(self.names) res.last_name = self.last_name res.attrs = copy(self.attrs) return res def add_const(self, const): # FIXME: should fix this method # self.names.append(const.__name__) if '__file__' in dir(const): self.names[const.__name__] = const.__file__ else: self.names[const.__name__] = '' self.last_name = const.__name__ self.module = const self.attrs.clear() # print self.names # raise Exception(repr(self.names)) def add_type(self, other): # print "ADDING TYPE TO MODULE: %r" % other if other.names: # FIXME: quick hack for modules if self.module is not None and (set(other.names) <= set( self.names)): return self.names.update(other.names) self.last_name = other.last_name self.module = other.module self._set_attrs() def _set_attrs(self): cur_name = self.last_name try: smt = self.module.cfg[cur_name].bbs['exit'].states['normal'].smtbl self.attrs.clear() for name, v in smt.globals.items(): self.attrs[name] = v except KeyError, msg: print "Warning: %r" % sys.exc_info()[1] self.attrs.clear()
def __init__(self, loader=None): self.loader = loader or ihooks.ModuleLoader() cimport.set_loader(self.find_import_module)
# The contents of this file are subject to the Mozilla Public License Version