本文整理汇总了Python中zope.app.zapi.queryMultiAdapter函数的典型用法代码示例。如果您正苦于以下问题:Python queryMultiAdapter函数的具体用法?Python queryMultiAdapter怎么用?Python queryMultiAdapter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了queryMultiAdapter函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUnnamedViewThatProvidesAnInterface
def testUnnamedViewThatProvidesAnInterface(self):
ob = Ob()
self.assertEqual(
zapi.queryMultiAdapter((ob, Request(IR)), IV), None)
xmlconfig(StringIO(template %
'''
<view factory="zope.app.component.tests.views.V1"
for="zope.app.component.tests.views.IC"
type="zope.app.component.tests.views.IR"
/>
'''
))
v = zapi.queryMultiAdapter((ob, Request(IR)), IV)
self.assertEqual(v, None)
xmlconfig(StringIO(template %
'''
<view factory="zope.app.component.tests.views.V1"
for="zope.app.component.tests.views.IC"
type="zope.app.component.tests.views.IR"
provides="zope.app.component.tests.views.IV"
/>
'''
))
v = zapi.queryMultiAdapter((ob, Request(IR)), IV)
self.assertEqual(v.__class__, V1)
示例2: testView_w_multiple_factories
def testView_w_multiple_factories(self):
xmlconfig(StringIO(template %
'''
<view name="test"
factory="zope.app.component.tests.adapter.A1
zope.app.component.tests.adapter.A2
zope.app.component.tests.adapter.A3
zope.app.component.tests.views.V1"
for="zope.app.component.tests.views.IC"
type="zope.app.component.tests.views.IV"/>
'''
))
ob = Ob()
# The view should be a V1 around an A3, around an A2, around
# an A1, anround ob:
view = zapi.queryMultiAdapter((ob, Request(IV)), name=u'test')
self.assertEqual(view.__class__, V1)
a3 = view.context
self.assertEqual(a3.__class__, A3)
a2 = a3.context[0]
self.assertEqual(a2.__class__, A2)
a1 = a2.context[0]
self.assertEqual(a1.__class__, A1)
self.assertEqual(a1.context[0], ob)
示例3: _initSettings
def _initSettings(self, obj, profile_id, obj_path):
stool = getToolByName(self, 'portal_setup', None)
if stool is None:
return
context = stool._getImportContext(profile_id)
file_ids = context.listDirectory('types')
for file_id in file_ids or ():
filename = 'types/%s' % file_id
body = context.readDataFile(filename)
if body is None:
continue
root = parseString(body).documentElement
new_id = str(root.getAttribute('name'))
if not new_id:
# BBB: for CMF 1.5 profiles
new_id = str(root.getAttribute('id'))
if new_id != obj_path[0]:
continue
# BBB: for CMF 1.5 profiles
meta_type = str(root.getAttribute('kind'))
if not meta_type:
meta_type = str(root.getAttribute('meta_type'))
if meta_type != self.klass.meta_type:
continue
importer = zapi.queryMultiAdapter((obj, context), IBody)
if importer is None:
continue
importer.body = body
return
示例4: _extractCachingPolicies
def _extractCachingPolicies(self):
fragment = self._doc.createDocumentFragment()
for policy_id, policy in self.context.listPolicies():
exporter = zapi.queryMultiAdapter((policy, self.environ), INode)
if exporter:
fragment.appendChild(exporter.node)
return fragment
示例5: _initIndexes
def _initIndexes(self, node):
for child in node.childNodes:
if child.nodeName != 'index':
continue
if child.hasAttribute('deprecated'):
continue
zcatalog = self.context
idx_id = str(child.getAttribute('name'))
if idx_id not in zcatalog.indexes():
extra = _extra()
for sub in child.childNodes:
if sub.nodeName == 'extra':
name = str(sub.getAttribute('name'))
value = str(sub.getAttribute('value'))
setattr(extra, name, value)
extra = extra.__dict__ and extra or None
meta_type = str(child.getAttribute('meta_type'))
zcatalog.addIndex(idx_id, meta_type, extra)
idx = zcatalog._catalog.getIndex(idx_id)
importer = zapi.queryMultiAdapter((idx, self.environ), INode)
if importer:
importer.node = child
示例6: _initSettings
def _initSettings(self, obj, profile_id, obj_path):
stool = getToolByName(self, 'portal_setup', None)
if stool is None:
return
context = stool._getImportContext(profile_id)
body = context.readDataFile('actions.xml')
if body is None:
return
settings_node = None
root = parseString(body).documentElement
for node in root.childNodes:
if node.nodeName != 'object':
continue
for obj_id in obj_path:
for child in node.childNodes:
if child.nodeName != 'object':
continue
if child.getAttribute('name') != obj_id:
continue
if child.getAttribute('meta_type') == self.klass.meta_type:
settings_node = child
else:
node = child
break
importer = zapi.queryMultiAdapter((obj, context), INode)
if importer is None:
return
importer.node = settings_node
return
示例7: _exportNode
def _exportNode(self):
"""Export the object as a DOM node.
"""
node = self._getObjectNode('index')
for set in self.context.filteredSets.values():
exporter = zapi.queryMultiAdapter((set, self.environ), INode)
node.appendChild(exporter.node)
return node