本文整理汇总了Python中nevow.util.qual函数的典型用法代码示例。如果您正苦于以下问题:Python qual函数的具体用法?Python qual怎么用?Python qual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handlerWithIdentifier
def test_handlerWithIdentifier(self):
gatherer = LiveGatherer()
ctx = context.WovenContext()
ctx.remember(gatherer, livepage.IClientHandle)
oneQual = util.qual(oneHandler)
twoQual = util.qual(twoHandler)
## Subscribe both handlers to the same identifier
livepage.handler(oneHandler, identifier="same")(ctx, None)
livepage.handler(twoHandler, identifier="same")(ctx, None)
gatherer.handleInput("same")
self.assertEquals(gatherer.heard, ["one", "two"])
示例2: getComponent
def getComponent(self, interface, registry=None, default=None):
"""Create or retrieve an adapter for the given interface.
If such an adapter has already been created, retrieve it from the cache
that this instance keeps of all its adapters. Adapters created through
this mechanism may safely store system-specific state.
If you want to register an adapter that will be created through
getComponent, but you don't require (or don't want) your adapter to be
cached and kept alive for the lifetime of this Componentized object,
set the attribute 'temporaryAdapter' to True on your adapter class.
If you want to automatically register an adapter for all appropriate
interfaces (with addComponent), set the attribute 'multiComponent' to
True on your adapter class.
"""
registry = getRegistry(registry)
k = util.qual(interface)
if self._adapterCache.has_key(k):
return self._adapterCache[k]
else:
adapter = interface.__adapt__(self)
if hasattr(adapter, "__class__"):
fixClassImplements(adapter.__class__)
if adapter is not None and adapter is not _Nothing and not (
hasattr(adapter, "temporaryAdapter") and
adapter.temporaryAdapter):
self._adapterCache[k] = adapter
if (hasattr(adapter, "multiComponent") and
adapter.multiComponent):
self.addComponent(adapter)
return adapter
示例3: remember
def remember(self, adapter, interface=None):
"""Remember an object that implements some interfaces.
Later, calls to .locate which are passed an interface implemented
by this object will return this object.
If the 'interface' argument is supplied, this object will only
be remembered for this interface, and not any of
the other interfaces it implements.
"""
if interface is None:
interfaceList = megaGetInterfaces(adapter)
if not interfaceList:
interfaceList = [dataqual]
else:
interfaceList = [qual(interface)]
if self._remembrances is None:
self._remembrances = {}
for interface in interfaceList:
self._remembrances[interface] = adapter
return self
示例4: locate
def locate(self, interface, depth=1, _default=object()):
"""Locate an object which implements a given interface.
Objects will be searched through the context stack top
down.
"""
key = qual(interface)
currentContext = self
while True:
if depth < 0:
full = []
while True:
try:
full.append(self.locate(interface, len(full)+1))
except KeyError:
break
#print "full", full, depth
if full:
return full[depth]
return None
_remembrances = currentContext._remembrances
if _remembrances is not None:
rememberedValue = _remembrances.get(key, _default)
if rememberedValue is not _default:
depth -= 1
if not depth:
return rememberedValue
# Hook for FactoryContext and other implementations of complex locating
locateHook = currentContext.locateHook
if locateHook is not None:
result = locateHook(interface)
if result is not None:
currentContext.remember(result, interface)
return result
contextParent = currentContext.parent
if contextParent is None:
raise KeyError, "Interface %s was not remembered." % key
currentContext = contextParent
示例5: addComponent
def addComponent(self, component, ignoreClass=0, registry=None):
"""
Add a component to me, for all appropriate interfaces.
In order to determine which interfaces are appropriate, the component's
provided interfaces will be scanned.
If the argument 'ignoreClass' is True, then all interfaces are
considered appropriate.
Otherwise, an 'appropriate' interface is one for which its class has
been registered as an adapter for my class according to the rules of
getComponent.
@return: the list of appropriate interfaces
"""
if hasattr(component, "__class__"):
fixClassImplements(component.__class__)
for iface in declarations.providedBy(component):
if (ignoreClass or
(self.locateAdapterClass(self.__class__, iface, None, registry)
== component.__class__)):
self._adapterCache[util.qual(iface)] = component
示例6: megaGetInterfaces
def megaGetInterfaces(adapter):
return [qual(x) for x in providedBy(adapter)]
示例7: megaGetInterfaces
def megaGetInterfaces(adapter):
adrs = [qual(x) for x in compy.getInterfaces(adapter)]
## temporarily turn this off till we need it
if False: #hasattr(adapter, '_adapterCache'):
adrs.extend(adapter._adapterCache.keys())
return adrs
示例8: configure
def configure(self, boundTo, results):
raise NotImplementedError, "Implement in %s" % util.qual(self.__class__)
示例9: __repr__
def __repr__(self):
if self.interface is None:
return "Object(None)"
return "Object(interface=%s)" % util.qual(self.interface)
示例10: unsetComponent
def unsetComponent(self, interfaceClass):
"""Remove my component specified by the given interface class."""
del self._adapterCache[util.qual(interfaceClass)]
示例11: from_string
def from_string(self, string):
if not self.convert_from:
raise NotImplementedError("Implement in %s" %
util.qual(self.__class__))
self.value = self.convert_from(string)
示例12: to_string
def to_string(self):
if not self.convert_to:
raise NotImplementedError("Implement in %s" %
util.qual(self.__class__))
return self.convert_to()
示例13: coerce
def coerce(self, val, configurable):
raise NotImplementedError, "Implement in %s" % util.qual(self.__class__)
示例14: __repr__
def __repr__(self):
if self.iface is not None:
return "%s(interface=%s)" % (self.__class__.__name__, util.qual(self.iface))
return self.__class__.__name__ + "()"
示例15: setComponent
def setComponent(self, interfaceClass, component):
"""
"""
if hasattr(component, "__class__"):
fixClassImplements(component.__class__)
self._adapterCache[util.qual(interfaceClass)] = component