Python twisted.python.reflect.namedModule() Examples
The following are 20
code examples of twisted.python.reflect.namedModule().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.python.reflect
, or try the search function
.
Example #1
Source File: rebuild.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def latestClass(oldClass): """ Get the latest version of a class. """ module = reflect.namedModule(oldClass.__module__) newClass = getattr(module, oldClass.__name__) newBases = [latestClass(base) for base in newClass.__bases__] try: # This makes old-style stuff work newClass.__bases__ = tuple(newBases) return newClass except TypeError: if newClass.__module__ == "__builtin__": # __builtin__ members can't be reloaded sanely return newClass ctor = getattr(newClass, '__metaclass__', type) return ctor(newClass.__name__, tuple(newBases), dict(newClass.__dict__))
Example #2
Source File: test_doc.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def modulesInPackage(self, packageName, package): docless = [] directory = path.dirname(package.__file__) for modfile in glob.glob(path.join(directory, '*.py')): moduleName = inspect.getmodulename(modfile) if moduleName == '__init__': # These are tested by test_packages. continue elif moduleName in ('spelunk_gnome','gtkmanhole'): # argh special case pygtk evil argh. How does epydoc deal # with this? continue try: module = reflect.namedModule('.'.join([packageName, moduleName])) except Exception, e: # print moduleName, "misbehaved:", e pass else: if not inspect.getdoc(module): docless.append(modfile)
Example #3
Source File: lore.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def getProcessor(input, output, config): plugins = oldplugin._getPlugIns("lore") for plug in plugins: if plug.tapname == input: module = plug.load() break else: plugins = newplugin.getPlugins(IProcessor) for plug in plugins: if plug.name == input: module = reflect.namedModule(plug.moduleName) break else: # try treating it as a module name try: module = reflect.namedModule(input) except ImportError: print '%s: no such input: %s' % (sys.argv[0], input) return try: return process.getProcessor(module, output, config) except process.NoProcessorError, e: print "%s: %s" % (sys.argv[0], e)
Example #4
Source File: widgets.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def getChild(self, path, request): if path == '': # ZOOP! if isinstance(self, Widget): return self.pageFactory(self) widget = self.getWidget(path, request) if widget: if isinstance(widget, resource.Resource): return widget else: p = self.pageFactory(widget) p.isLeaf = getattr(widget,'isLeaf',0) return p elif self.paths.has_key(path): prefix = getattr(sys.modules[self.__module__], '__file__', '') if prefix: prefix = os.path.abspath(os.path.dirname(prefix)) return static.File(os.path.join(prefix, self.paths[path])) elif path == '__reload__': return self.pageFactory(Reloader(map(reflect.namedModule, [self.__module__] + self.modules))) else: return error.NoResource("No such child resource in gadget.")
Example #5
Source File: test_doc.py From python-for-android with Apache License 2.0 | 6 votes |
def modulesInPackage(self, packageName, package): docless = [] directory = path.dirname(package.__file__) for modfile in glob.glob(path.join(directory, '*.py')): moduleName = inspect.getmodulename(modfile) if moduleName == '__init__': # These are tested by test_packages. continue elif moduleName in ('spelunk_gnome','gtkmanhole'): # argh special case pygtk evil argh. How does epydoc deal # with this? continue try: module = reflect.namedModule('.'.join([packageName, moduleName])) except Exception, e: # print moduleName, "misbehaved:", e pass else: if not inspect.getdoc(module): docless.append(modfile)
Example #6
Source File: test_doc.py From python-for-android with Apache License 2.0 | 6 votes |
def testModules(self): """Looking for docstrings in all modules.""" docless = [] for packageName in self.packageNames: if packageName in ('twisted.test',): # because some stuff in here behaves oddly when imported continue try: package = reflect.namedModule(packageName) except ImportError, e: # This is testing doc coverage, not importability. # (Really, I don't want to deal with the fact that I don't # have pyserial installed.) # print e pass else: docless.extend(self.modulesInPackage(packageName, package))
Example #7
Source File: lore.py From python-for-android with Apache License 2.0 | 6 votes |
def getProcessor(input, output, config): plugins = plugin.getPlugins(IProcessor) for plug in plugins: if plug.name == input: module = reflect.namedModule(plug.moduleName) break else: # try treating it as a module name try: module = reflect.namedModule(input) except ImportError: print '%s: no such input: %s' % (sys.argv[0], input) return try: return process.getProcessor(module, output, config) except process.NoProcessorError, e: print "%s: %s" % (sys.argv[0], e)
Example #8
Source File: rebuild.py From python-for-android with Apache License 2.0 | 6 votes |
def latestClass(oldClass): """ Get the latest version of a class. """ module = reflect.namedModule(oldClass.__module__) newClass = getattr(module, oldClass.__name__) newBases = [latestClass(base) for base in newClass.__bases__] try: # This makes old-style stuff work newClass.__bases__ = tuple(newBases) return newClass except TypeError: if newClass.__module__ == "__builtin__": # __builtin__ members can't be reloaded sanely return newClass ctor = getattr(newClass, '__metaclass__', type) return ctor(newClass.__name__, tuple(newBases), dict(newClass.__dict__))
Example #9
Source File: rebuild.py From learn_python3_spider with MIT License | 6 votes |
def latestClass(oldClass): """ Get the latest version of a class. """ module = reflect.namedModule(oldClass.__module__) newClass = getattr(module, oldClass.__name__) newBases = [latestClass(base) for base in newClass.__bases__] try: # This makes old-style stuff work newClass.__bases__ = tuple(newBases) return newClass except TypeError: if newClass.__module__ in ("__builtin__", "builtins"): # __builtin__ members can't be reloaded sanely return newClass ctor = type(newClass) # The value of type(newClass) is the metaclass # in both Python 2 and 3, except if it was old-style. if _isClassType(ctor): ctor = getattr(newClass, '__metaclass__', type) return ctor(newClass.__name__, tuple(newBases), dict(newClass.__dict__))
Example #10
Source File: tap.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def postOptions(self): """ Set up conditional defaults and check for dependencies. If SSL is not available but an HTTPS server was configured, raise a L{UsageError} indicating that this is not possible. If no server port was supplied, select a default appropriate for the other options supplied. """ if self['https']: try: reflect.namedModule('OpenSSL.SSL') except ImportError: raise usage.UsageError("SSL support not installed") if self['port'] is None: if not _PY3 and self['personal']: path = os.path.expanduser( os.path.join('~', distrib.UserDirectory.userSocketName)) self['port'] = 'unix:' + path else: self['port'] = 'tcp:8080'
Example #11
Source File: test_reflect.py From python-for-android with Apache License 2.0 | 5 votes |
def test_namedModuleLookup(self): """ L{namedModule} should return the module object for the name it is passed. """ self.assertIdentical( reflect.namedModule("twisted.python.reflect"), reflect)
Example #12
Source File: test_reflect.py From learn_python3_spider with MIT License | 5 votes |
def test_namedModuleLookup(self): """ L{namedModule} should return the module object for the name it is passed. """ from twisted.python import monkey self.assertIs( reflect.namedModule("twisted.python.monkey"), monkey)
Example #13
Source File: tap.py From learn_python3_spider with MIT License | 5 votes |
def postOptions(self): """ Set up conditional defaults and check for dependencies. If SSL is not available but an HTTPS server was configured, raise a L{UsageError} indicating that this is not possible. If no server port was supplied, select a default appropriate for the other options supplied. """ if self['port'] is not None: self['ports'].append(self['port']) if self['https'] is not None: try: reflect.namedModule('OpenSSL.SSL') except ImportError: raise usage.UsageError("SSL support not installed") sslStrport = 'ssl:port={}:privateKey={}:certKey={}'.format( self['https'], self['privkey'], self['certificate'], ) self['ports'].append(sslStrport) if len(self['ports']) == 0: if self['personal']: path = os.path.expanduser( os.path.join('~', distrib.UserDirectory.userSocketName)) self['ports'].append('unix:' + path) else: self['ports'].append('tcp:8080')
Example #14
Source File: app.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def installReactor(reactor): if reactor: reflect.namedModule(reactorTypes[reactor]).install()
Example #15
Source File: util.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def moduleMovedForSplit(origModuleName, newModuleName, moduleDesc, projectName, projectURL, globDict): from twisted.python import reflect modoc = """ %(moduleDesc)s This module is DEPRECATED. It has been split off into a third party package, Twisted %(projectName)s. Please see %(projectURL)s. This is just a place-holder that imports from the third-party %(projectName)s package for backwards compatibility. To use it, you need to install that package. """ % {'moduleDesc': moduleDesc, 'projectName': projectName, 'projectURL': projectURL} #origModule = reflect.namedModule(origModuleName) try: newModule = reflect.namedModule(newModuleName) except ImportError: raise ImportError("You need to have the Twisted %s " "package installed to use %s. " "See %s." % (projectName, origModuleName, projectURL)) # Populate the old module with the new module's contents for k,v in vars(newModule).items(): globDict[k] = v globDict['__doc__'] = modoc import warnings warnings.warn("%s has moved to %s. See %s." % (origModuleName, newModuleName, projectURL), DeprecationWarning, stacklevel=3) return
Example #16
Source File: test_reflect.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_namedModuleLookup(self): """ L{namedModule} should return the module object for the name it is passed. """ from twisted.python import monkey self.assertIs( reflect.namedModule("twisted.python.monkey"), monkey)
Example #17
Source File: test_reflect.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testModuleLookup(self): self.assertEquals(reflect.namedModule("twisted.python.reflect"), reflect)
Example #18
Source File: test_doc.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testPackages(self): """Looking for docstrings in all packages.""" docless = [] for packageName in self.packageNames: try: package = reflect.namedModule(packageName) except Exception, e: # This is testing doc coverage, not importability. # (Really, I don't want to deal with the fact that I don't # have pyserial installed.) # print e pass else: if not inspect.getdoc(package): docless.append(package.__file__.replace('.pyc','.py'))
Example #19
Source File: test_split_compat.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def testCompatibility(self): for oldName, newName in movedModules: try: old = reflect.namedModule(oldName) new = reflect.namedModule(newName) except ImportError, e: continue for someName in vars(new): if someName == '__doc__': continue self.assertIdentical(getattr(old, someName), getattr(new, someName))
Example #20
Source File: test_upgrading.py From axiom with MIT License | 5 votes |
def loadSchemaModule(name): schemaModules.append(namedModule(name)) result = schemaModules[-1] choose(None) return result