本文整理汇总了Python中twisted.python.reflect.namedObject函数的典型用法代码示例。如果您正苦于以下问题:Python namedObject函数的具体用法?Python namedObject怎么用?Python namedObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了namedObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unjelly
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])
示例2: remote_registerClasses
def remote_registerClasses(self, *args):
"""
Instructs my broker to register the classes specified by the
argument(s).
The classes will be registered for B{all} jobs, and are specified by
their string representations::
<package(s).module.class>
"""
modules = []
for stringRep in args:
# Load the class for the string representation
cls = reflect.namedObject(stringRep)
# Register instances of the class, including its type and module
pb.setUnjellyableForClass(stringRep, cls)
if cls.__module__ not in modules:
modules.append(cls.__module__)
# Try to build the modules for the classes in case they've changed
# since the last run
for module in modules:
try:
rebuild(reflect.namedModule(module), doLog=False)
except:
pass
示例3: autocrud
def autocrud(nodes, name, modelFQN):
model = reflect.namedObject(modelFQN)
schema = [a for a in dir(model) if isinstance(getattr(model, a), PropertyColumn)]
if "id" not in schema:
print "Sorry, this code isn't clever enough to auto-crud models with no id"
return
listCols = ["id"]
if "name" in schema:
listCols.append("name")
crudCols = schema[:]
crudCols.remove("id")
if "name" in crudCols:
crudCols.remove("name")
crudCols.insert(0, "name")
listColumns = ", ".join('"%s"' % c for c in listCols)
crudColumns = textwrap.fill(", ".join('"%s"' % c for c in crudCols))
nodeContent = crudTemplate % {
"listColumns": listColumns,
"crudColumns": crudColumns,
"model": modelFQN.rsplit(".", 1)[1],
"node": name,
}
skeleton.createNode(nodes, name, createIndex=False, nodeContent=nodeContent)
示例4: nevowify
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'):
f = open(newFilename, 'w')
f.write(s)
f.close()
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)
f = open(newFilename, 'wb')
clonedNode.writexml(f)
f.close()
示例5: __init__
def __init__(self, methodName):
if type(methodName) is types.StringType:
self.testClass = reflect.namedObject('.'.join(methodName.split('.')[:-1]))
methodName = methodName.split('.')[-1]
else:
self.testClass = methodName.im_class
self.methodName = methodName.__name__
示例6: receiveChild
def receiveChild(self, obj, ready_deferred=None):
assert not isinstance(obj, Deferred)
assert ready_deferred is None
if self.finished:
raise BananaError("ClassUnslicer only accepts one string")
self.finished = True
# TODO: taste here!
self.klass = reflect.namedObject(obj)
示例7: _unjelly_function
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
示例8: _unjelly_function
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
示例9: _unjelly_class
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
示例10: _unjelly_class
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: removeComponent
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
示例12: _unjelly_class
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
示例13: unjelly
def unjelly(self, obj):
if type(obj) is not types.ListType:
return obj
jelType = obj[0]
if not self.taster.isTypeAllowed(jelType):
raise InsecureJelly(jelType)
regClass = unjellyableRegistry.get(jelType)
if regClass is not None:
if isinstance(regClass, ClassType):
inst = _Dummy() # XXX chomp, chomp
inst.__class__ = regClass
method = inst.unjellyFor
elif isinstance(regClass, type):
# regClass.__new__ does not call regClass.__init__
inst = regClass.__new__(regClass)
method = inst.unjellyFor
else:
method = regClass # this is how it ought to be done
val = method(self, obj)
if hasattr(val, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return val
regFactory = unjellyableFactoryRegistry.get(jelType)
if regFactory is not None:
state = self.unjelly(obj[1])
inst = regFactory(state)
if hasattr(inst, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return inst
thunk = getattr(self, '_unjelly_%s'%jelType, None)
if thunk is not None:
ret = thunk(obj[1:])
else:
nameSplit = jelType.split('.')
modName = '.'.join(nameSplit[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly(
"Module %s not allowed (in type %s)." % (modName, jelType))
clz = namedObject(jelType)
if not self.taster.isClassAllowed(clz):
raise InsecureJelly("Class %s not allowed." % jelType)
if hasattr(clz, "__setstate__"):
ret = _newInstance(clz)
state = self.unjelly(obj[1])
ret.__setstate__(state)
else:
state = self.unjelly(obj[1])
ret = _newInstance(clz, state)
if hasattr(clz, 'postUnjelly'):
self.postCallbacks.append(ret.postUnjelly)
return ret
示例14: run
def run():
config = Options()
try:
config.parseOptions()
except usage.error as e:
print("%s: %s" % (sys.argv[0], e))
print()
c = getattr(config, 'subOptions', config)
print(str(c))
sys.exit(1)
subconfig = config.subOptions
subcommandFunction = reflect.namedObject(subconfig.subcommandFunction)
sys.exit(subcommandFunction(subconfig))
示例15: receiveClose
def receiveClose(self):
# you could attempt to do some value-checking here, but there would
# probably still be holes
#obj = Dummy()
klass = reflect.namedObject(self.classname)
assert type(klass) == types.ClassType # TODO: new-style classes
obj = instance(klass, {})
setInstanceState(obj, self.d)
self.protocol.setObject(self.count, obj)
self.deferred.callback(obj)
return obj, None