[ZCM] [ZC] 1169/19 Resolve "DTML misses new builtins"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Fri Jan 16 14:32:40 EST 2004


Issue #1169 Update (Resolve) "DTML misses new builtins"
 Status Resolved, Zope/bug+solution medium
To followup, visit:
  http://zope.org/Collectors/Zope/1169

==============================================================
= Resolve - Entry #19 by Brian on Jan 16, 2004 2:32 pm

 Status: Accepted => Resolved

Fixed for 2.6.4, 2.7 and the cvs head.

-Brian
________________________________________
= Comment - Entry #17 by tseaver on Jan 12, 2004 4:49 pm

I think I have a fix for this issue checked in on the
2.6 branch.  The munging of 'guarded_min' and 'guarded_max'
into the DTML namespace, with corresponding tests, belongs
in the AccessControl;  DocumentTemplate ought not to
depend on AccessControl (a cycle).

Note as well that the 2.6 version does *not* expose the
new 2.2 and 2.3 builtins ('iter', 'sum', 'enumerate');
this is by design, as otherwise we will encourage breakage
due to inadvertent use of later idioms.

The 2.7 fix is harder, due to the odd import cycles.
________________________________________
= Comment - Entry #16 by Dirk.Datzert on Jan 11, 2004 3:56 pm

Hi all,

I searched a better place for patching safe_builtins of DT_Utils. I found it in lib/python/OFS/__init__.py

====================================
--- __init__.py.orig    Sun Jan 11 21:30:34 2004
+++ __init__.py Sun Jan 11 21:29:09 2004
@@ -10,3 +10,9 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
+
+from DocumentTemplate.DT_Util import NotBindable, TemplateDict
+from AccessControl.ZopeGuards import guarded_max, guarded_min
+
+TemplateDict.__dict__['min'] = NotBindable(guarded_min)
+TemplateDict.__dict__['max'] = NotBindable(guarded_max)
====================================

This patch works for Zope 2.6.3 and Zope 2.7.0b4

Regards,
Dirk
________________________________________
= Comment - Entry #15 by ctheune on Jan 11, 2004 2:02 pm

DBTab is already integral part of Zope 2.7 no need (and way) to use the DBTab product with it.
________________________________________
= Comment - Entry #14 by Dirk.Datzert on Jan 11, 2004 2:01 pm

I would say that the following import test shows some kind of recursive-loop-import ? 

datzert1:/usr/local/Zope-2.7.0-b4 # python2.3
Python 2.3.3 (#1, Jan 11 2004, 19:22:42)
[GCC 2.95.3 20010315 (SuSE)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from DocumentTemplate import DT_Util
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/Zope-2.7.0-b4/lib/python/DocumentTemplate/__init__.py", line 22, in ?
    from DocumentTemplate import String, File, HTML, HTMLDefault, HTMLFile
  File "/usr/local/Zope-2.7.0-b4/lib/python/DocumentTemplate/DocumentTemplate.py", line 112, in ?
    from DT_String import String, File
  File "/usr/local/Zope-2.7.0-b4/lib/python/DocumentTemplate/DT_String.py", line 17, in ?
    from DT_Util import ParseError, InstanceDict, TemplateDict, render_blocks, str
  File "/usr/local/Zope-2.7.0-b4/lib/python/DocumentTemplate/DT_Util.py", line 61, in ?
    from AccessControl.ZopeGuards import guarded_min, guarded_max
  File "/usr/local/Zope-2.7.0-b4/lib/python/AccessControl/__init__.py", line 16, in ?
    import DTML
  File "/usr/local/Zope-2.7.0-b4/lib/python/AccessControl/DTML.py", line 18, in ?
    from DocumentTemplate import DT_Util
ImportError: cannot import name DT_Util
________________________________________
= Comment - Entry #13 by Dirk.Datzert on Jan 11, 2004 1:44 pm

I tried the patch it with a plain Zope 2.7.0b4 installation and got an error on startup:

Error: The object named by "DBTab.ClassFactories.autoClassFactory" could not be imported
(line 822 in file:///usr/local/Zope-2.7.0-b4/etc/zope.conf)
For help, use /usr/local/Zope-2.7.0-b4/lib/python/Zope/Startup/run.py -h

No ZEO is needed to reproduce this error.
________________________________________
= Comment - Entry #12 by Dirk.Datzert on Jan 11, 2004 5:23 am

Installed DBTab 1.2 on Zope 2.6.3 (without ZEO)
The patch works fine for me.
________________________________________
= Comment - Entry #11 by dtremea on Jan 10, 2004 7:49 pm

After apply Dirk Datzert patch (on 2.7-branch version, and using ZEO) Zope bombs with:

Error: The object named by "DBTab.ClassFactories.autoClassFactory" could not be imported
(line 794 in file:///usr/local/zope/Instance1/etc/zope.conf)
For help, use /usr/local/zope/Zope/lib/python/Zope/Startup/zopectl.py -h
________________________________________
= Comment - Entry #10 by Dirk.Datzert on Jan 10, 2004 5:03 pm

Hi all,

I attached a simple and fast patch.
Don't know if it is the best way.

I tried to attach the patch but that doesn't work.

======================================
--- DT_Util.py.orig     Sat Jan 10 22:58:45 2004
+++ DT_Util.py  Sat Jan 10 22:56:43 2004
@@ -58,6 +58,11 @@
     else:
         d[name] = f
 
+from AccessControl.ZopeGuards import guarded_min, guarded_max
+
+d['min'] = NotBindable(guarded_min)
+d['max'] = NotBindable(guarded_max)
+
 if LIMITED_BUILTINS:
     # Replace certain builtins with limited versions.
     from RestrictedPython.Limits import limited_builtins
======================================

Regards,
Dirk


________________________________________
= Comment - Entry #9 by ctheune on Jan 10, 2004 12:11 pm

I have created a branch:

ctheune-bug1169-branch

this includes a new unit-test for DTML in lib/python/DocumentTemplate/tests/testDTML.py and is currently breaking.

It tests the "new builtins" to return correct results.

Tres: You can use this for reference.


________________________________________
= Comment - Entry #8 by Dirk.Datzert on Jan 10, 2004 11:10 am

Hi all,

Zope 2.6.3 itself is broken as it is not possible to rename objects via ZMI. 

lib/python/OFS/dtml/renameForm.dtml:27:   "_.max(40,_.len(getId())+4)">" value="&dtml-id;" />  

I get an AttributeError for max !

Regards,
Dirk
________________________________________
= Comment - Entry #7 by ctheune on Jan 9, 2004 6:18 pm

Btw: I think Tres' mentioned second solution is better,
but maybe somebody can tell me if it's not. 
________________________________________
= Comment - Entry #6 by ctheune on Jan 9, 2004 6:17 pm

Yuppie: Isn't that because OOM became integral part of ZOpe 2.7? Zope 2.6 actually does not.

Anyway. Zope-2_6-branch returns this for me:

<TemplateDict object at 0x94e4388>

when I use the earlier mentioned DTML code with _.min


________________________________________
= Comment - Entry #5 by yuppie on Jan 9, 2004 6:11 pm

FYI: Zope-2_7-branch and HEAD use the same dtml line as OrderedObjectManager. You can see the Zope 2.7 main.dtml is broken if you add more than one item to an OrderedFolder.
________________________________________
= Comment - Entry #4 by ctheune on Jan 9, 2004 2:56 pm

I checked the smallest possible case:

do

<dtml-var "_.min([1,2])">

in a Zope 2.6.3 of your choice in a dtml-Method. This should break at   /Zope-2.6-CVS/lib/python/DocumentTemplate/DT_Util.py(205)eval()

________________________________________
= Assign - Entry #3 by ctheune on Jan 9, 2004 2:40 pm

Well, one thing I found is this:

_.range(1,_.min(5,_.len(objectIds())))

which is from the OrderedObjectManager that monkeypatches
ObjectManager.manage_main

OOM is available from http://zope.org/Members/mjablonski/OrderedObjectManager/1.4.1/OrderedObjectManager-1.4.1.tar.gz

I would like to see those very widely used Products not to be broken by a bugfix release.


________________________________________
= Accept - Entry #2 by tseaver on Jan 9, 2004 1:03 pm

 Status: Pending => Accepted

 Supporters added: tseaver

I see two issues here:

 1. Because DocumentTemplate is not supposed to depend on
    AccessControl, DT_Utils does its own dance with the
    RestrictedPython version of 'safe_builtins'.
    AccessControl.DTML already stomps on
    DT_Util.TemplateDict, adding the various 'Security*'
    names.  We should just make it stomp the "correct"
    'safe_builtins' as well.

 2. AccessControl.ZopeGuards makes a copy of
    RestrictedPythonGuards.safe_builtins, and then
    morphs it.  Given that we expect other packages
    (e.g., page templates, python scripts) to depend
    on the "abstract" RestrictedPython, rather than the
    "concrete" AccessControl, we should perhaps be
    morphing the RestrictedPython version in place.
________________________________________
= Request - Entry #1 by tseaver on Jan 9, 2004 12:56 pm

Christian Theune asked:

> I have the strange feeling that somebody forgot to include the
> AccessControl.ZopeGuard.safe_builtins for DTML.
>
> See DT_Utils.py around line 56 and the corresponding imports as well
> as the definition of safe_builtins in ZopeGuard.py.
>
> Could someone verify this?


==============================================================




More information about the Zope-Collector-Monitor mailing list