本文整理汇总了Python中twisted.python.reflect.namedModule方法的典型用法代码示例。如果您正苦于以下问题:Python reflect.namedModule方法的具体用法?Python reflect.namedModule怎么用?Python reflect.namedModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.reflect
的用法示例。
在下文中一共展示了reflect.namedModule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postOptions
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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'
示例2: latestClass
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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__))
示例3: latestClass
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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__))
示例4: getProcessor
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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)
示例5: testModules
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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))
示例6: modulesInPackage
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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)
示例7: getChild
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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.")
示例8: getProcessor
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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)
示例9: test_namedModuleLookup
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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)
示例10: postOptions
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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')
示例11: test_namedModuleLookup
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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)
示例12: installReactor
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
def installReactor(reactor):
if reactor:
reflect.namedModule(reactorTypes[reactor]).install()
示例13: moduleMovedForSplit
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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
示例14: testModuleLookup
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
def testModuleLookup(self):
self.assertEquals(reflect.namedModule("twisted.python.reflect"), reflect)
示例15: testPackages
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedModule [as 别名]
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'))