本文整理汇总了Python中twisted.python.reflect.namedObject方法的典型用法代码示例。如果您正苦于以下问题:Python reflect.namedObject方法的具体用法?Python reflect.namedObject怎么用?Python reflect.namedObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.reflect
的用法示例。
在下文中一共展示了reflect.namedObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _buildFailure
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _buildFailure(self, error, errorClass, frames):
"""
Helper to build a C{Failure} with some traceback.
@param error: An C{Exception} instance.
@param error: The class name of the C{error} class.
@param frames: A flat list of strings representing the information need
to approximatively rebuild C{Failure} frames.
@return: A L{Failure} instance with enough information about a test
error.
"""
if _PY3:
errorClass = errorClass.decode("utf-8")
errorType = namedObject(errorClass)
failure = Failure(error, errorType)
for i in range(0, len(frames), 3):
failure.frames.append(
(frames[i], frames[i + 1], int(frames[i + 2]), [], []))
return failure
示例2: _buildFailure
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _buildFailure(self, error, errorClass, frames):
"""
Helper to build a C{Failure} with some traceback.
@param error: An C{Exception} instance.
@param error: The class name of the C{error} class.
@param frames: A flat list of strings representing the information need
to approximatively rebuild C{Failure} frames.
@return: A L{Failure} instance with enough information about a test
error.
"""
errorType = namedObject(errorClass)
failure = Failure(error, errorType)
for i in range(0, len(frames), 3):
failure.frames.append(
(frames[i], frames[i + 1], int(frames[i + 2]), [], []))
return failure
示例3: applyUpgrade
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def applyUpgrade(self, fp):
"""
Apply the data upgrade .py files to the database.
"""
# Find the module function we need to execute
try:
module = getModule(__name__)
module = ".".join(module.name.split(".")[:-1]) + ".upgrades." + fp.basename()[:-3] + ".doUpgrade"
doUpgrade = namedObject(module)
except ImportError:
msg = "Failed data upgrade: %s" % (fp.basename()[:-4],)
self.log.error(msg)
raise RuntimeError(msg)
self.log.warn("Applying data upgrade: {module}", module=module)
yield doUpgrade(self.sqlStore)
示例4: removeComponent
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def removeComponent(self, component):
"""
Remove the given component from me entirely, for all interfaces for which
it has been registered.
@return: a list of the interfaces that were removed.
"""
if (isinstance(component, types.ClassType) or
isinstance(component, types.TypeType)):
warnings.warn("passing interface to removeComponent, you probably want unsetComponent", DeprecationWarning, 1)
self.unsetComponent(component)
return [component]
l = []
for k, v in self._adapterCache.items():
if v is component:
del self._adapterCache[k]
l.append(reflect.namedObject(k))
return l
示例5: nevowify
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def nevowify(filename, linkrel, ext, url, templ, options=None, outfileGenerator=tree.getOutputFileName):
if options is None:
options = {}
pclass = options['pageclass']
pclass = reflect.namedObject(pclass)
page = pclass(docFactory=loaders.htmlfile(filename))
s = page.renderString()
s = ____wait(s)
newFilename = outfileGenerator(filename, ext)
if options.has_key('nolore'):
open(newFilename, 'w').write(s)
return
doc = parseStringAndReport(s)
clonedNode = templ.cloneNode(1)
tree.munge(doc, clonedNode, linkrel, os.path.dirname(filename), filename, ext,
url, options, outfileGenerator)
tree.makeSureDirectoryExists(newFilename)
clonedNode.writexml(open(newFilename, 'wb'))
示例6: removeComponent
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def removeComponent(self, component):
"""
Remove the given component from me entirely, for all interfaces for which
it has been registered.
@return: a list of the interfaces that were removed.
"""
l = []
for k, v in list(self._adapterCache.items()):
if v is component:
del self._adapterCache[k]
l.append(reflect.namedObject(k))
return l
示例7: unjelly
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def unjelly(self, obj):
if type(obj) is not list:
return obj
jelTypeBytes = obj[0]
if not self.taster.isTypeAllowed(jelTypeBytes):
raise InsecureJelly(jelTypeBytes)
regClass = unjellyableRegistry.get(jelTypeBytes)
if regClass is not None:
method = getattr(_createBlank(regClass), "unjellyFor", regClass)
return self._maybePostUnjelly(method(self, obj))
regFactory = unjellyableFactoryRegistry.get(jelTypeBytes)
if regFactory is not None:
return self._maybePostUnjelly(regFactory(self.unjelly(obj[1])))
jelTypeText = nativeString(jelTypeBytes)
thunk = getattr(self, '_unjelly_%s' % jelTypeText, None)
if thunk is not None:
return thunk(obj[1:])
else:
nameSplit = jelTypeText.split('.')
modName = '.'.join(nameSplit[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly(
"Module %s not allowed (in type %s)." % (modName, jelTypeText))
clz = namedObject(jelTypeText)
if not self.taster.isClassAllowed(clz):
raise InsecureJelly("Class %s not allowed." % jelTypeText)
return self._genericUnjelly(clz, obj[1])
示例8: _unjelly_class
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_class(self, rest):
cname = nativeString(rest[0])
clist = cname.split(nativeString('.'))
modName = nativeString('.').join(clist[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("module %s not allowed" % modName)
klaus = namedObject(cname)
objType = type(klaus)
if objType not in (_OldStyleClass, type):
raise InsecureJelly(
"class %r unjellied to something that isn't a class: %r" % (
cname, klaus))
if not self.taster.isClassAllowed(klaus):
raise InsecureJelly("class not allowed: %s" % qual(klaus))
return klaus
示例9: removeComponent
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def removeComponent(self, component):
"""
Remove the given component from me entirely, for all interfaces for which
it has been registered.
@return: a list of the interfaces that were removed.
"""
l = []
for k, v in self._adapterCache.items():
if v is component:
del self._adapterCache[k]
l.append(reflect.namedObject(k))
return l
示例10: _unjelly_class
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_class(self, rest):
clist = rest[0].split('.')
modName = '.'.join(clist[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("module %s not allowed" % modName)
klaus = namedObject(rest[0])
objType = type(klaus)
if objType not in (types.ClassType, types.TypeType):
raise InsecureJelly(
"class %r unjellied to something that isn't a class: %r" % (
rest[0], klaus))
if not self.taster.isClassAllowed(klaus):
raise InsecureJelly("class not allowed: %s" % qual(klaus))
return klaus
示例11: _unjelly_function
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_function(self, rest):
modSplit = rest[0].split('.')
modName = '.'.join(modSplit[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("Module not allowed: %s"% modName)
# XXX do I need an isFunctionAllowed?
function = namedObject(rest[0])
return function
示例12: _unjelly_class
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_class(self, rest):
clist = string.split(rest[0], '.')
modName = string.join(clist[:-1], '.')
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("module %s not allowed" % modName)
klaus = namedObject(rest[0])
if type(klaus) is not types.ClassType:
raise InsecureJelly("class %s unjellied to something that isn't a class: %s" % (repr(name), repr(klaus)))
if not self.taster.isClassAllowed(klaus):
raise InsecureJelly("class not allowed: %s" % qual(klaus))
return klaus
示例13: _unjelly_function
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_function(self, rest):
modSplit = string.split(rest[0], '.')
modName = string.join(modSplit[:-1], '.')
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("Module not allowed: %s"% modName)
# XXX do I need an isFunctionAllowed?
function = namedObject(rest[0])
return function
示例14: _unjelly_class
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_class(self, rest):
clist = string.split(rest[0], '.')
# if len(rest) > 0: warn("reference numbers will be out of sync")
modName = string.join(clist[:-1], '.')
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("module %s not allowed" % modName)
klaus = namedObject(rest[0])
if type(klaus) is not types.ClassType:
raise InsecureJelly("class %s unjellied to something that isn't a class: %s" % (repr(name), repr(klaus)))
if not self.taster.isClassAllowed(klaus):
raise InsecureJelly("class not allowed: %s" % qual(klaus))
self.resolveReference(klaus)
return klaus
示例15: _unjelly_function
# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedObject [as 别名]
def _unjelly_function(self, rest):
modSplit = string.split(rest[0], '.')
# if len(rest) > 0: warn("reference numbers will be out of sync")
modName = string.join(modSplit[:-1], '.')
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("Module not allowed: %s"% modName)
# XXX do I need an isFunctionAllowed?
function = namedObject(rest[0])
self.resolveReference(function)
return function