[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/ It turns out we'll still have to wrap content providers because there might

2007-09-01 Thread Philipp von Weitershausen
Log message for revision 79429:
  It turns out we'll still have to wrap content providers because there might
  be legacy implementations out there needing it.  Therefore we need to keep
  our own ProviderExpression implementation.
  
  Added legacy tests for content providers and viewlets
  

Changed:
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/providerexpression.py
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
  A   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/legacymanager.pt
  A   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/legacyprovider.pt
  U   Zope/branches/philikon-aq/lib/python/Products/PageTemplates/Expressions.py

-=-
Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/providerexpression.py
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/providerexpression.py
2007-09-01 17:37:52 UTC (rev 79428)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/providerexpression.py
2007-09-01 20:16:02 UTC (rev 79429)
@@ -12,11 +12,52 @@
 #
 ##
 Provider expression.
-
-This module solely exists for backwards-compatibility.  Please import
-TALESProviderExpression from zope.contentprovider.tales.
 
+import zope.event
+import zope.interface
+import zope.component
 
-# BBB
-from zope.contentprovider.tales import TALESProviderExpression \
- as Z2ProviderExpression
+from zope.tales import expressions
+from zope.contentprovider import interfaces, tales
+from zope.location.interfaces import ILocation
+
+from Acquisition.interfaces import IAcquirer
+
+class Z2ProviderExpression(expressions.StringExpr):
+zope.interface.implements(interfaces.ITALESProviderExpression)
+
+# This is mostly a copy of
+# zope.contentprovider.tales.TALESProviderExpression's __call__
+# method.
+def __call__(self, econtext):
+name = super(Z2ProviderExpression, self).__call__(econtext)
+context = econtext.vars['context']
+request = econtext.vars['request']
+view = econtext.vars['view']
+
+# Try to look up the provider.
+provider = zope.component.queryMultiAdapter(
+(context, request, view), interfaces.IContentProvider, name)
+
+# Provide a useful error message, if the provider was not found.
+if provider is None:
+raise interfaces.ContentProviderLookupError(name)
+
+# add the __name__ attribute if it implements ILocation
+if ILocation.providedBy(provider):
+provider.__name__ = name
+
+# ATTN: This is where we are different from
+# TALESProviderExpression: We support Acquisition wrapping.
+if IAcquirer.providedBy(provider):
+provider = provider.__of__(context)
+
+# Insert the data gotten from the context
+tales.addTALNamespaceData(provider, econtext)
+
+# Stage 1: Do the state update.
+zope.event.notify(interfaces.BeforeUpdateEvent(provider, request))
+provider.update()
+
+# Stage 2: Render the HTML content.
+return provider.render()

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
2007-09-01 17:37:52 UTC (rev 79428)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
2007-09-01 20:16:02 UTC (rev 79429)
@@ -18,6 +18,8 @@
 better) still work.
 
 import Acquisition
+from zope.interface import implements
+from zope.contentprovider.interfaces import IContentProvider
 from Products.Five import BrowserView
 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
 
@@ -54,3 +56,52 @@
 class ImplicitWithTemplate(Acquisition.Implicit):
 
 template = ViewPageTemplateFile('falcon.pt')
+
+
+class ExplicitContentProvider(Acquisition.Explicit):
+implements(IContentProvider)
+
+def __init__(self, context, request, view):
+self.context = context
+self.request = request
+self.view = view
+# Normally, a content provider should set __parent__ to view
+# or context.  This one doesn't do this on purpose to ensure
+# it works without.
+
+def update(self):
+# Make sure that the content provider is acquisition wrapped.
+assert self.aq_parent == self.context
+assert self.aq_base == self
+
+def render(self):
+return 'Content provider inheriting from Explicit'
+
+class ExplicitViewlet(Acquisition.Explicit):
+
+def 

[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/ We do need to do some wrapping when objects are found via namespace

2007-09-01 Thread Philipp von Weitershausen
Log message for revision 79432:
  We do need to do some wrapping when objects are found via namespace
  traversal.
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/OFS/Traversable.py
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
  U   Zope/branches/philikon-aq/lib/python/ZPublisher/BaseRequest.py

-=-
Modified: Zope/branches/philikon-aq/lib/python/OFS/Traversable.py
===
--- Zope/branches/philikon-aq/lib/python/OFS/Traversable.py 2007-09-01 
20:59:12 UTC (rev 79431)
+++ Zope/branches/philikon-aq/lib/python/OFS/Traversable.py 2007-09-01 
23:52:33 UTC (rev 79432)
@@ -23,6 +23,7 @@
 from AccessControl import Unauthorized
 from AccessControl.ZopeGuards import guarded_getattr
 from Acquisition import Acquired, aq_inner, aq_parent, aq_acquire, aq_base
+from Acquisition.interfaces import IAcquirer
 from zExceptions import NotFound
 from ZODB.POSException import ConflictError
 from OFS.interfaces import ITraversable
@@ -193,6 +194,8 @@
 try:
 next = namespaceLookup(
 ns, nm, obj, aq_acquire(self, 'REQUEST'))
+if IAcquirer.providedBy(next):
+next = next.__of__(obj)
 if restricted and not validate(
 obj, obj, name, next):
 raise Unauthorized(name)

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
2007-09-01 20:59:12 UTC (rev 79431)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
2007-09-01 23:52:33 UTC (rev 79432)
@@ -18,7 +18,10 @@
 better) still work.
 
 import Acquisition
+import OFS.SimpleItem
+
 from zope.interface import implements
+from zope.traversing.interfaces import ITraversable
 from zope.contentprovider.interfaces import IContentProvider
 from Products.Five import BrowserView
 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@@ -115,3 +118,19 @@
 
 def render(self):
 return 'BrowserView viewlet'
+
+
+class LegacyNamespace(object):
+implements(ITraversable)
+
+def __init__(self, context, request):
+self.context = context
+self.request = request
+
+def traverse(self, name, ignored):
+return LegacyNamespaceObject(name)
+
+class LegacyNamespaceObject(OFS.SimpleItem.SimpleItem):
+
+def __init__(self, name):
+self.id = name

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml  
2007-09-01 20:59:12 UTC (rev 79431)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml  
2007-09-01 23:52:33 UTC (rev 79432)
@@ -112,4 +112,24 @@
   permission=zope.Public
   /
 
+  !-- Namespace traversal --
+
+  adapter
+  for=*
+  factory=.aqlegacy.LegacyNamespace
+  name=aqlegacy
+  /
+  adapter
+  for=* *
+  factory=.aqlegacy.LegacyNamespace
+  name=aqlegacy
+  /
+
+  browser:page
+  for=.aqlegacy.LegacyNamespaceObject
+  name=index.html
+  template=falcon.pt
+  permission=zope.Public
+  /
+
 /configure
\ No newline at end of file

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
 2007-09-01 20:59:12 UTC (rev 79431)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
 2007-09-01 23:52:33 UTC (rev 79432)
@@ -141,6 +141,28 @@
   Viewlet inheriting from Explicit/p
 
 
+Testing namespace traversal
+===
+
+Namespace traversal can turn up objects during traversal without
+attribute access.  That means they might not be wrapped by default.
+Here we make sure that they are wrapped and that things like the
+request can be acquired.
+
+First let's try ``restrictedTraverse()``:
+
+   foo = self.folder.restrictedTraverse('++aqlegacy++foo')
+   import Acquisition
+   Acquisition.aq_acquire(foo, 'REQUEST')
+  HTTPRequest, URL=http://nohost
+
+Now let's try URL traversal:
+
+   
browser.open('http://localhost/test_folder_1_/++aqlegacy++foo/index.html')
+   print browser.contents
+  pThe falcon has taken flight/p
+
+
 Clean up