More API BBB: Make method signatures of pt_render and pt_errors compatible with

old Zope 2 code.
parent 5e0f612a
......@@ -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 @@ class PageTemplate(ExtensionClass.Base,
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 @@ class PageTemplate(ExtensionClass.Base,
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})
......@@ -25,10 +25,10 @@ from Shared.DC.Scripts.Script import Script
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 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable):
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)
......
......@@ -35,9 +35,9 @@ from AccessControl.Permissions import view_management_screens
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 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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)
......
......@@ -59,6 +59,7 @@ class ZPTRegressions(unittest.TestCase):
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 @@ class ZPTMacros(unittest.TestCase):
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=''):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment