[Zope-Checkins] SVN: Products.Five/branches/ajung-zpt-end-game/browser/ We no longer need to do monkey business with the engine etc. At least I

Philipp von Weitershausen philikon at philikon.de
Tue May 9 05:27:00 EDT 2006


Log message for revision 68056:
  We no longer need to do monkey business with the engine etc. At least I
  very much hope so...
  

Changed:
  D   Products.Five/branches/ajung-zpt-end-game/browser/ReuseUtils.py
  D   Products.Five/branches/ajung-zpt-end-game/browser/TrustedExpression.py
  U   Products.Five/branches/ajung-zpt-end-game/browser/pagetemplatefile.py

-=-
Deleted: Products.Five/branches/ajung-zpt-end-game/browser/ReuseUtils.py
===================================================================
--- Products.Five/branches/ajung-zpt-end-game/browser/ReuseUtils.py	2006-05-09 09:20:32 UTC (rev 68055)
+++ Products.Five/branches/ajung-zpt-end-game/browser/ReuseUtils.py	2006-05-09 09:26:59 UTC (rev 68056)
@@ -1,32 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004, 2005 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.
-#
-##############################################################################
-"""Utils to be reused
-
-$Id$
-"""
-from new import function
-
-def rebindFunction(f,rebindDir=None,**rebinds):
-  '''return *f* with some globals rebound.'''
-  d= {}
-  if rebindDir : d.update(rebindDir)
-  if rebinds: d.update(rebinds)
-  if not d: return f
-  f= getattr(f,'im_func',f)
-  fd= f.func_globals.copy()
-  fd.update(d)
-  nf= function(f.func_code,fd,f.func_name,f.func_defaults or ())
-  nf.__doc__= f.__doc__
-  if f.__dict__ is not None: nf.__dict__= f.__dict__.copy()
-  return nf

Deleted: Products.Five/branches/ajung-zpt-end-game/browser/TrustedExpression.py
===================================================================
--- Products.Five/branches/ajung-zpt-end-game/browser/TrustedExpression.py	2006-05-09 09:20:32 UTC (rev 68055)
+++ Products.Five/branches/ajung-zpt-end-game/browser/TrustedExpression.py	2006-05-09 09:26:59 UTC (rev 68056)
@@ -1,141 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004, 2005 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.
-#
-##############################################################################
-"""Trusted expression
-
-$Id$
-"""
-from Products.PageTemplates.PythonExpr import PythonExpr
-from Products.PageTemplates.Expressions import \
-     SubPathExpr, PathExpr, \
-     StringExpr, \
-     getEngine, installHandlers,\
-     SecureModuleImporter
-
-from Products.Five.browser.ProviderExpression import ProviderExpr
-
-from ReuseUtils import rebindFunction
-
-ModuleImporter = SecureModuleImporter
-
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.interface import implements, Interface
-from zope.publisher.browser import setDefaultSkin
-from zope.traversing.namespace import nsParse, namespaceLookup
-from zope.component import queryMultiAdapter
-
-class FakeRequest(dict):
-  implements(IBrowserRequest)
-
-  def getURL(self):
-    return "http://codespeak.net/z3/five"
-
-def trustedTraverse(ob, path, ignored,):
-  if not path: return self
-
-  get = getattr
-  has = hasattr
-  N = None
-  M = rebindFunction # artifical marker
-
-  if isinstance(path, str): path = path.split('/')
-  else: path=list(path)
-
-  REQUEST = get(ob, 'REQUEST', None)
-  if REQUEST is None:
-    REQUEST=FakeRequest()
-    setDefaultSkin(REQUEST)
-  REQUEST['TraversalRequestNameStack'] = path
-  path.reverse()
-  pop=path.pop
-
-  if len(path) > 1 and not path[0]:
-    # Remove trailing slash
-    path.pop(0)
-
-  if not path[-1]:
-    # If the path starts with an empty string, go to the root first.
-    pop()
-    self=ob.getPhysicalRoot()
-
-  object = ob
-  while path:
-    name=pop()
-    __traceback_info__ = path, name
-
-    if name == '..':
-      o=getattr(object, 'aq_parent', M)
-      if o is not M:
-        object=o
-        continue
-
-    if name and name[:1] in '@+':
-      # Process URI segment parameters.
-      ns, nm = nsParse(name)
-      if ns:
-        try:
-          o = namespaceLookup(ns, nm, object, REQUEST).__of__(object)
-        except TraversalError:
-          raise KeyError(name)
-        object = o
-        continue
-
-    t=get(object, '__bobo_traverse__', M)
-    if t is not M: o=t(REQUEST, name)
-    else:
-      o = get(object, name, M)
-      if o is M:
-        try: o = object[name]
-        except (AttributeError, TypeError): # better exception
-            o = queryMultiAdapter((object, REQUEST), Interface, name)
-            if o is not None:
-                o = o.__of__(object)
-            else:
-                raise AttributeError(name)
-    object = o
-
-  return object
-
-
-class SubPathExpr(SubPathExpr):
-  _eval = rebindFunction(SubPathExpr._eval.im_func,
-                         restrictedTraverse=trustedTraverse,
-                         )
-
-class PathExpr(PathExpr):
-  __init__ = rebindFunction(PathExpr.__init__.im_func,
-                            SubPathExpr=SubPathExpr,
-                            )
-
-class StringExpr(StringExpr):
-  __init__ = rebindFunction(StringExpr.__init__.im_func,
-                            PathExpr=PathExpr,
-                            )
-
-
-installHandlers = rebindFunction(installHandlers,
-                                 PathExpr=PathExpr,
-                                 StringExpr=StringExpr,
-                                 PythonExpr=PythonExpr,
-                                 )
-
-def installHandlers2(engine):
-    installHandlers(engine)
-    engine.registerType('provider', ProviderExpr)
-
-_engine=None
-getEngine = rebindFunction(getEngine,
-                           _engine=_engine,
-                           installHandlers=installHandlers2
-                           )
-

Modified: Products.Five/branches/ajung-zpt-end-game/browser/pagetemplatefile.py
===================================================================
--- Products.Five/branches/ajung-zpt-end-game/browser/pagetemplatefile.py	2006-05-09 09:20:32 UTC (rev 68055)
+++ Products.Five/branches/ajung-zpt-end-game/browser/pagetemplatefile.py	2006-05-09 09:26:59 UTC (rev 68056)
@@ -19,14 +19,11 @@
 
 from Globals import package_home
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
+from Products.PageTemplates.Expressions import SecureModuleImporter
 
 from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 
-from Products.Five.browser.ReuseUtils import rebindFunction
-from Products.Five.browser.TrustedExpression import getEngine, ModuleImporter
-
-
 class ZopeTwoPageTemplateFile(PageTemplateFile):
     """A strange hybrid between Zope 2 and Zope 3 page template.
 
@@ -64,12 +61,6 @@
             path = package_home(_prefix)
         return path
 
-    _cook = rebindFunction(PageTemplateFile._cook,
-                           getEngine=getEngine)
-
-    pt_render = rebindFunction(PageTemplateFile.pt_render,
-                               getEngine=getEngine)
-
     def pt_getContext(self):
         try:
             root = self.getPhysicalRoot()
@@ -92,7 +83,7 @@
              'options': {},
              'root': root,
              'request': request,
-             'modules': ModuleImporter,
+             'modules': SecureModuleImporter,
              }
         if view is not None:
             c['view'] = view



More information about the Zope-Checkins mailing list