Example #1
0
    def load_module(self, fullname):
        if fullname in sys.modules:
            return sys.modules[fullname]

        split = fullname.split('.')
        if split[-1][0].islower():
            # it's a package/module
            mod = module(fullname)
            mod.__dict__.update({
                '__loader__': self,
                '__path__': [],
                '__file__': '<java>',
            })
            sys.modules[fullname] = mod

            if self.classlist.supportsPackageImport():
                # get the list of classes in package and add them as attributes
                # to the module
                classlist = self.classlist.getClassNames(fullname)
                if classlist:
                    for name in classlist:
                        try:
                            setattr(mod, name.split('.')[-1], forName(name))
                        except Exception:
                            pass
        else:
            # It's a Java class, in general we will only reach here if
            # self.classlist.supportsPackageImport() is False (ie the class
            # has not already been imported and set on the module).
            parentModName = '.'.join(split[0:-1])
            parentMod = sys.modules[parentModName]
            return parentMod.__getattr__(split[-1])
        return mod
Example #2
0
 def __getattr__(self, name):
     try:
         return super(module, self).__getattribute__(name)
     except AttributeError as ae:
         clazz = forName('{0}.{1}'.format(self.__name__, name))
         setattr(self, name, clazz)
         return clazz
Example #3
0
 def __getattr__(self, name):
     try:
         return super(module, self).__getattribute__(name)
     except AttributeError as ae:
         try:
             clazz = forName('{0}.{1}'.format(self.__name__, name))
             setattr(self, name, clazz)
             return clazz
         except Exception:
             # should raise AttributeError, not JepException
             raise ae
Example #4
0
File: hook.py Project: Kroisse/jep
 def __getattr__(self, name):
     try:
         return super(module, self).__getattribute__(name)
     except AttributeError as ae:
         try:
             clazz = forName('{0}.{1}'.format(self.__name__, name))
             setattr(self, name, clazz)
             return clazz
         except Exception:
             # should raise AttributeError, not JepException
             raise ae
Example #5
0
 def __getattr__(self, name):
     try:
         return super(module, self).__getattribute__(name)
     except AttributeError as ae:
         subpkgs = self.__classEnquirer__.getSubPackages(self.__name__)
         if subpkgs and name in subpkgs:
             fullname = self.__name__ + '.' + name
             mod = makeModule(fullname, self.__loader__, self.__classEnquirer__)
             return mod
         elif name == '__all__':
             return self.__dir__()
         else:
             # assume it is a class and attempt the import
             clazz = forName('{0}.{1}'.format(self.__name__, name))
             setattr(self, name, clazz)
             return clazz
Example #6
0
 def __getattr__(self, name):
     try:
         return super(module, self).__getattribute__(name)
     except AttributeError as ae:
         subpkgs = self.__classEnquirer__.getSubPackages(self.__name__)
         if subpkgs and name in subpkgs:
             fullname = self.__name__ + '.' + name
             mod = makeModule(fullname, self.__loader__,
                              self.__classEnquirer__)
             return mod
         elif name == '__all__':
             return self.__dir__()
         else:
             # assume it is a class and attempt the import
             clazz = forName('{0}.{1}'.format(self.__name__, name))
             setattr(self, name, clazz)
             return clazz
Example #7
0
    def load_module(self, fullname):
        if fullname in sys.modules:
            return sys.modules[fullname]

        mod = module(fullname)
        mod.__dict__.update({
            '__loader__': self,
            '__path__': [],
            '__file__': '<java>',
        })
        sys.modules[fullname] = mod

        # list of classes in package
        classlist = self.classlist.get(fullname)
        if classlist:
            for name in classlist:
                try:
                    setattr(mod, name.split('.')[-1], forName(name))
                except Exception:
                    pass
        return mod
Example #8
0
File: hook.py Project: Kroisse/jep
    def load_module(self, fullname):
        if fullname in sys.modules:
            return sys.modules[fullname]

        mod = module(fullname)
        mod.__dict__.update({
            '__loader__': self,
            '__path__': [],
            '__file__': '<java>',
        })
        sys.modules[fullname] = mod

        # list of classes in package
        classlist = self.classlist.get(fullname)
        if classlist:
            for name in classlist:
                try:
                    setattr(mod, name.split('.')[-1], forName(name))
                except Exception:
                    pass
        return mod
Example #9
0
 def __init__(self):
     self.classlist = forName('jep.ClassList').getInstance()
Example #10
0
 def __init__(self, classlist=None):
     if classlist:
         self.classlist = classlist
     else:
         self.classlist = forName('jep.ClassList').getInstance()
Example #11
0
 def __init__(self, classEnquirer=None):
     if classEnquirer:
         self.classEnquirer = classEnquirer
     else:
         self.classEnquirer = forName('jep.ClassList').getInstance()
Example #12
0
 def __init__(self, classEnquirer=None):
     if classEnquirer:
         self.classEnquirer = classEnquirer
     else:
         self.classEnquirer = forName('jep.ClassList').getInstance()
Example #13
0
File: hook.py Project: Kroisse/jep
 def __init__(self):
     self.classlist = forName('jep.ClassList').getInstance()