[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py Simplify by using more machinery from Zope 3 (which we can thanks to IBrowserPUblisher

2007-07-30 Thread Philipp von Weitershausen
Log message for revision 78482:
  Simplify by using more machinery from Zope 3 (which we can thanks to 
IBrowserPUblisher
  support since Zope 2.10)
  

Changed:
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py

-=-
Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py
===
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py 
2007-07-30 20:59:22 UTC (rev 78481)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/metaconfigure.py 
2007-07-30 21:10:41 UTC (rev 78482)
@@ -29,10 +29,10 @@
 from zope.publisher.interfaces.browser import IBrowserRequest, \
  IDefaultBrowserLayer
 
-from zope.app.publisher.browser.viewmeta import pages as zope_app_pages
-from zope.app.publisher.browser.viewmeta import view as zope_app_view
-from zope.app.publisher.browser.viewmeta import providesCallable, \
- _handle_menu, _handle_for
+import zope.app.publisher.browser.viewmeta
+import zope.app.pagetemplate.simpleviewclass
+from zope.app.publisher.browser.viewmeta import (providesCallable,
+ _handle_menu, _handle_for)
 
 from Products.Five.browser import BrowserView
 from Products.Five.browser.resource import FileResourceFactory
@@ -159,7 +159,7 @@
 args = (new_class,)
 )
 
-class pages(zope_app_pages):
+class pages(zope.app.publisher.browser.viewmeta.pages):
 
 def page(self, _context, name, attribute='__call__', template=None,
  menu=None, title=None):
@@ -172,7 +172,7 @@
 
 # view (named view with pages)
 
-class view(zope_app_view):
+class view(zope.app.publisher.browser.viewmeta.view):
 
 def __call__(self):
 (_context, name, for_, permission, layer, class_,
@@ -389,33 +389,23 @@
 args = (new_class,)
 )
 
-#
-# mixin classes / class factories
-#
+class ViewMixinForAttributes(BrowserView,
+ zope.app.publisher.browser.viewmeta.simple):
 
-class ViewMixinForAttributes(BrowserView):
+# For some reason, the 'simple' baseclass doesn't implement this
+# mandatory method (see https://bugs.launchpad.net/zope3/+bug/129296)
+def browserDefault(self, request):
+return getattr(self, self.__page_attribute__), ()
 
-# we have an attribute that we can simply tell ZPublisher to go to
-def __browser_default__(self, request):
-return self, (self.__page_attribute__,)
+# __call__ should have the same signature as the original method
+@property
+def __call__(self):
+return getattr(self, self.__page_attribute__)
 
-# this is technically not needed because ZPublisher finds our
-# attribute through __browser_default__; but we also want to be
-# able to call pages from python modules, PythonScripts or ZPT
-__call__ = property(lambda self: getattr(self, self.__page_attribute__))
+class ViewMixinForTemplates(BrowserView,
+zope.app.pagetemplate.simpleviewclass.simple):
+pass
 
-class ViewMixinForTemplates(BrowserView):
-
-# short cut to get to macros more easily
-def __getitem__(self, name):
-if name == 'macros':
-return self.index.macros
-return self.index.macros[name]
-
-# make the template publishable
-def __call__(self, *args, **kw):
-return self.index(self, *args, **kw)
-
 def makeClassForTemplate(filename, globals=None, used_for=None,
  bases=(), cdict=None, name=u''):
 # XXX needs to deal with security from the bases?

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages Assert that views of the form

2007-07-30 Thread Philipp von Weitershausen
Log message for revision 78483:
  Assert that views of the form
  
class MyView(BrowserView):
  
__call__ = ViewPageTemplateFile('...')
  
  work.
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.py
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.zcml
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages_ftest.txt

-=-
Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.py
===
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.py   
2007-07-30 21:10:41 UTC (rev 78482)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.py   
2007-07-30 21:11:50 UTC (rev 78483)
@@ -16,6 +16,7 @@
 $Id$
 
 from Products.Five import BrowserView
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
 
 class SimpleView(BrowserView):
 More docstring. Please Zope
@@ -39,6 +40,10 @@
 def __call__(self):
 return uI was __call__()'ed
 
+class CallTemplate(BrowserView):
+
+__call__ = ViewPageTemplateFile('falcon.pt')
+
 class CallableNoDocstring:
 
 def __call__(self):

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.zcml
===
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.zcml 
2007-07-30 21:10:41 UTC (rev 78482)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages.zcml 
2007-07-30 21:11:50 UTC (rev 78483)
@@ -161,6 +161,13 @@
   permission=zope2.Public
   /
 
+  browser:page
+  for=Products.Five.tests.testing.simplecontent.ISimpleContent
+  class=.pages.CallTemplate
+  name=calltemplate.html
+  permission=zope2.Public
+  /
+
   !-- pages from methods/functions/callables that don't have docstrings --
   browser:pages
   for=Products.Five.tests.testing.simplecontent.ISimpleContent

Modified: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages_ftest.txt
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages_ftest.txt
2007-07-30 21:10:41 UTC (rev 78482)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/pages_ftest.txt
2007-07-30 21:11:50 UTC (rev 78483)
@@ -144,7 +144,15 @@
   ...
   I was __call__()'ed
 
+or a __call__ object that's callable, such as a ViewPageTemplateFile:
 
+   print http(r'''
+  ... GET /test_folder_1_/testoid/calltemplate.html HTTP/1.1
+  ... ''')
+  HTTP/1.1 200 OK
+  ...
+  pThe falcon has taken flight/p
+
 Clean up
 
 

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] SVN: Zope/branches/philikon-aq/lib/python/Products/Five/browser/ Some legacy tests. And a (disabled) failing one that tests the __of__

2007-07-30 Thread Philipp von Weitershausen
Log message for revision 78489:
  Some legacy tests.  And a (disabled) failing one that tests the __of__
  behaviour of BrowserView.  Well, when I say failing I should really say
  segfaulting :/
  

Changed:
  U   Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py
  A   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
  A   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml
  A   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy_ftest.txt
  U   
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/test_pages.py

-=-
Modified: Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py
===
--- Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py  
2007-07-30 21:58:11 UTC (rev 78488)
+++ Zope/branches/philikon-aq/lib/python/Products/Five/browser/__init__.py  
2007-07-30 22:02:14 UTC (rev 78489)
@@ -15,18 +15,21 @@
 
 $Id$
 
-
+import Acquisition
 import zope.publisher.browser
 
-from Acquisition import aq_chain
-from Acquisition import aq_inner
-
 class BrowserView(zope.publisher.browser.BrowserView):
 
 # BBB for code that expects BrowserView to still inherit from
 # Acquisition.Explicit.
 
 def __of__(self, context):
+# Technically this isn't in line with the way Acquisition's
+# __of__ works.  With Acquisition, you get a wrapper around
+# the original object and only that wrapper's parent is the
+# new context.  Here we change the original object.
+#self.__parent__ = context  # ugh. segfault!
+
 return self
 
 # XXX Classes which are still based on Acquisition and access
@@ -34,7 +37,7 @@
 # aq_chain. We do this here for BBB friendly purposes.
 
 def __getParent(self):
-return getattr(self, '_parent', aq_inner(self.context))
+return getattr(self, '_parent', Acquisition.aq_inner(self.context))
 
 def __setParent(self, parent):
 self._parent = parent
@@ -43,12 +46,8 @@
 
 # We provide the aq_* properties here for BBB
 
-@property
-def aq_base(self):
-return self
+aq_self = aq_inner = aq_base = property(lambda self: self)
 
-aq_self = aq_inner = aq_base
-
 @property
 def aq_chain(self):
-return aq_chain(self)
+return Acquisition.aq_chain(self)

Added: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
===
--- 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
(rev 0)
+++ 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
2007-07-30 22:02:14 UTC (rev 78489)
@@ -0,0 +1,53 @@
+##
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED AS IS AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##
+Legacy browser view tests.
+
+Here we nake sure that legacy implementations of views (e.g. those
+which mix-in one of the Acquisition base classes without knowing
+better) still work.
+
+import Acquisition
+from Products.Five import BrowserView
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+
+class LegacyAttributes(BrowserView):
+Make sure that accessing those old aq_* attributes on Five
+BrowserViews still works, even though BrowserView may not be an
+Acquisition-decendant class anymore...
+
+
+def __call__(self):
+assert self.aq_parent == self.context
+assert self.aq_inner == self
+assert self.aq_base == self
+assert self.aq_self == self
+return repr([obj for obj in self.aq_chain])
+
+class Explicit(Acquisition.Explicit):
+
+def render(self):
+return 'Explicit'
+
+class ExplicitWithTemplate(Acquisition.Explicit):
+
+template = ViewPageTemplateFile('falcon.pt')
+
+class Implicit(Acquisition.Implicit):
+
+def render(self):
+return 'Implicit'
+
+class ImplicitWithTemplate(Acquisition.Implicit):
+
+template = ViewPageTemplateFile('falcon.pt')


Property changes on: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.py
___
Name: svn:eol-style
   + native

Added: 
Zope/branches/philikon-aq/lib/python/Products/Five/browser/tests/aqlegacy.zcml