[Zope-Checkins]
SVN: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/
More API BBB: Make method signatures of pt_render and
pt_errors compatible with
Philipp von Weitershausen
philikon at philikon.de
Sun May 21 09:43:47 EDT 2006
Log message for revision 68210:
More API BBB: Make method signatures of pt_render and pt_errors compatible with
old Zope 2 code.
Changed:
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplate.py
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplateFile.py
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
-=-
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplate.py 2006-05-21 12:58:08 UTC (rev 68209)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplate.py 2006-05-21 13:43:46 UTC (rev 68210)
@@ -14,11 +14,11 @@
$Id$
"""
+import sys
import ExtensionClass
import zope.pagetemplate.pagetemplate
from zope.tales.expressions import SimpleModuleImporter
from Products.PageTemplates.Expressions import getEngine
-from Products.PageTemplates.Expressions import SecureModuleImporter
##############################################################################
# BBB 2005/05/01 -- to be removed after 12 months
@@ -47,12 +47,13 @@
def pt_getEngine(self):
return getEngine()
- def pt_getContext(self, args=(), options={}):
- c = super(PageTemplate, self).pt_getContext(args, options)
- c.update({
- 'request': None,
- 'modules': SimpleModuleImporter(),
- })
+ def pt_getContext(self):
+ c = {'template': self,
+ 'options': {},
+ 'nothing': None,
+ 'request': None,
+ 'modules': SimpleModuleImporter(),
+ }
parent = getattr(self, 'aq_parent', None)
if parent is not None:
c['here'] = parent
@@ -63,3 +64,26 @@
parent = getattr(self, 'aq_parent', None)
c['root'] = self
return c
+
+ # these methods are reimplemented or duplicated here because of
+ # different call signatures in the Zope 2 world
+
+ def pt_render(self, source=False, extra_context={}):
+ c = self.pt_getContext()
+ c.update(extra_context)
+ return super(PageTemplate, self).pt_render(c, source=source)
+
+ def pt_errors(self, namespace={}):
+ self._cook_check()
+ err = self._v_errors
+ if err:
+ return err
+ try:
+ self.pt_render(source=True, extra_context=namespace)
+ except:
+ return ('Macro expansion failed', '%s: %s' % sys.exc_info()[:2])
+
+ def __call__(self, *args, **kwargs):
+ if not kwargs.has_key('args'):
+ kwargs['args'] = args
+ return self.pt_render(extra_context={'options': kwargs})
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplateFile.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplateFile.py 2006-05-21 12:58:08 UTC (rev 68209)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PageTemplateFile.py 2006-05-21 13:43:46 UTC (rev 68210)
@@ -25,10 +25,10 @@
from Shared.DC.Scripts.Signature import FuncCode
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter
+from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.ZopePageTemplate import guess_type
from zope.contenttype import guess_content_type
-from zope.pagetemplate.pagetemplate import PageTemplate
LOG = getLogger('PageTemplateFile')
@@ -121,7 +121,7 @@
try:
context = self.pt_getContext()
context.update(bound_names)
- return self.pt_render(context)
+ return self.pt_render(extra_context=bound_names)
finally:
security.removeContext(self)
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py 2006-05-21 12:58:08 UTC (rev 68209)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/ZopePageTemplate.py 2006-05-21 13:43:46 UTC (rev 68210)
@@ -35,9 +35,9 @@
from webdav.Lockable import ResourceLockedError
from webdav.WriteLockInterface import WriteLockInterface
from zope.contenttype import guess_content_type
-from zope.pagetemplate.pagetemplate import PageTemplate
from zope.pagetemplate.pagetemplatefile import sniff_type
+from Products.PageTemplates.PageTemplate import PageTemplate
from Products.PageTemplates.Expressions import getEngine
from Products.PageTemplates.Expressions import SecureModuleImporter
@@ -123,14 +123,6 @@
self.ZBindings_edit(self._default_bindings)
self.pt_edit(text, content_type, encoding)
- def pt_render(self, namespace, source=False, sourceAnnotations=False,
- showtal=False):
- if namespace is None:
- namespace = self.pt_getContext()
- return super(ZopePageTemplate, self).pt_render(namespace, source, sourceAnnotations,
- showtal)
-
-
def pt_getEngine(self):
return getEngine()
@@ -288,11 +280,7 @@
security.addContext(self)
try:
- # XXX: check the parameters for pt_render()! (aj)
- result = self.pt_render(self.pt_getContext())
-
-
-# result = self.pt_render(extra_context=bound_names)
+ result = self.pt_render(extra_context=bound_names)
if keyset is not None:
# Store the result in the cache.
self.ZCacheable_set(result, keywords=keyset)
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2006-05-21 12:58:08 UTC (rev 68209)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py 2006-05-21 13:43:46 UTC (rev 68210)
@@ -59,6 +59,7 @@
self.assertEqual(pt.document_src(), self.text)
class ZPTMacros(unittest.TestCase):
+
def setUp(self):
transaction.begin()
self.app = makerequest(Zope2.app())
@@ -98,9 +99,9 @@
request = self.app.REQUEST
self._addPT('pt1', text=self.text, REQUEST=request)
pt = self.app.pt1
- pt.pt_render(None, source=1)
- self.assertEqual(pt.pt_errors(None), None)
-
+ pt.pt_render(source=True)
+ self.assertEqual(pt.pt_errors(), None)
+
class DummyFileUpload:
def __init__(self, data='', filename='', content_type=''):
More information about the Zope-Checkins
mailing list