[Zope3-checkins] CVS: Zope3/src/zope/app/advanced - query.py:1.6

Sidnei da Silva sidnei at awkly.org
Thu Apr 1 13:27:16 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/advanced
In directory cvs.zope.org:/tmp/cvs-serv23146

Modified Files:
	query.py 
Log Message:
Make a query helper that uses Implicit acquisition, as well as making the acquisition package be importable. With tests.


=== Zope3/src/zope/app/advanced/query.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/advanced/query.py:1.5	Thu Apr  1 12:50:19 2004
+++ Zope3/src/zope/app/advanced/query.py	Thu Apr  1 13:26:43 2004
@@ -19,7 +19,10 @@
 $Id$
 """
 
+__metaclass__ = type
+
 from zope.interface import implements
+from zope.app.advanced.acquisition import Implicit
 
 def advancedQueryMechanism(arguments,action='query',
                            tabs=''):
@@ -27,7 +30,7 @@
     Use the advance query mechanism.
 
     Let's have a look at a typical query session using the mechanism:
-    
+
     >>> exit
     'Use Ctrl-D (i.e. EOF) to exit.'
     >>> quit
@@ -124,7 +127,7 @@
             '\n')+'\n'
     else:
         result=''
-        
+
     return (
         "%s\n%s\n%s" % (
         join(map(lambda d: d[0],desc), '\t'),
@@ -138,7 +141,7 @@
         )
 
 class AdvancedSuperClass:
-    
+
     def superHasAttr(self,attr):
         obj=self
 
@@ -185,3 +188,28 @@
             except: return vals
             x=x+1
         return vals
+
+def frobnost(item):
+    from zope.app import zapi
+    if hasattr(item, '_p_jar'):
+        item._p_jar._objects.append(zapi.getServiceManager(item))
+    td = zapi.getUtility(ITranslationDomain, name='zope')
+    item.title = td.translate(item.getId(),
+                              default=('all your base are '
+                                       'belong to us'),
+                              target_languate='zw_CH')
+    item._p_changed = True
+
+class Acquired(AdvancedSuperClass, Implicit):
+    """ Provides the same semantics as AdvancedSuperClass,
+    but mixing-in Acquisition.Implicit
+    """
+
+    def superValues(self, t):
+        items = super(Acquired, self).superValues(t)
+        return map(frobnost, items)
+
+    def superHasAttr(self, attr):
+        vals = super(Acquired, self).superHasAttr(attr)
+        ga = lambda x: hasattr(zapi.getAdapter(x, IContainer), attr)
+        return map(ga, vals)




More information about the Zope3-Checkins mailing list