[Checkins] SVN: Zope/trunk/ - Merge remaining changes from gsoc-python-2.5 branch. We now 'work' on Python 2.6

Sidnei da Silva sidnei at enfoldsystems.com
Sun Oct 26 01:59:00 EDT 2008


Log message for revision 92577:
   - Merge remaining changes from gsoc-python-2.5 branch. We now 'work' on Python 2.6

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/AccessControl/ImplC.py
  U   Zope/trunk/lib/python/AccessControl/ImplPython.py
  U   Zope/trunk/lib/python/AccessControl/ZopeGuards.py
  U   Zope/trunk/lib/python/AccessControl/__init__.py
  U   Zope/trunk/lib/python/AccessControl/cAccessControl.c
  U   Zope/trunk/lib/python/AccessControl/tests/actual_python.py
  U   Zope/trunk/lib/python/AccessControl/tests/testZopeGuards.py
  U   Zope/trunk/lib/python/Acquisition/_Acquisition.c
  U   Zope/trunk/lib/python/DocumentTemplate/DT_HTML.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_If.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_In.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_InSV.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Let.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Raise.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Return.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_String.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Try.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_UI.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Util.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_Var.py
  U   Zope/trunk/lib/python/DocumentTemplate/DT_With.py
  D   Zope/trunk/lib/python/DocumentTemplate/DocumentTemplate.py
  U   Zope/trunk/lib/python/DocumentTemplate/VSEval.py
  A   Zope/trunk/lib/python/DocumentTemplate/_DocumentTemplate.py
  U   Zope/trunk/lib/python/DocumentTemplate/__init__.py
  U   Zope/trunk/lib/python/DocumentTemplate/cDocumentTemplate.c
  U   Zope/trunk/lib/python/DocumentTemplate/html_quote.py
  U   Zope/trunk/lib/python/DocumentTemplate/pDocumentTemplate.py
  U   Zope/trunk/lib/python/OFS/CopySupport.py
  U   Zope/trunk/lib/python/OFS/SimpleItem.py
  U   Zope/trunk/lib/python/OFS/tests/testCopySupport.py
  U   Zope/trunk/lib/python/Products/Five/testbrowser.py
  U   Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py
  U   Zope/trunk/lib/python/Shared/DC/ZRDB/sqlvar.py
  U   Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
  U   Zope/trunk/lib/python/ZPublisher/tests/testPublish.py
  U   Zope/trunk/lib/python/ZServer/HTTPServer.py
  U   Zope/trunk/lib/python/ZServer/medusa/http_server.py
  U   Zope/trunk/lib/python/Zope2/App/startup.py
  U   Zope/trunk/lib/python/Zope2/App/tests/testExceptionHook.py
  U   Zope/trunk/lib/python/zExceptions/__init__.py
  U   Zope/trunk/utilities/mkzopeinstance.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/doc/CHANGES.txt	2008-10-26 05:59:00 UTC (rev 92577)
@@ -219,6 +219,13 @@
 
     Bugs Fixed
 
+
+      - Launchpad #280334: Fixed problem with 'timeout'
+        argument/attribute missing in testbrowser tests.
+
+      - Launchpad #282677: fixed implementation of guarded_map and
+        provided tests and implementation for guarded_zip (RestrictedPython).
+
       - Lauchpad #143736,#271395: fixed AttributeError' on _ltid in TempStorage
 
       - 'AccessControl.ZopeGuards.guarded_import' mapped some Unauthorized
@@ -475,7 +482,19 @@
 
       - Prevent ZPublisher from insering incorrect <base/> tags into the
         headers of plain html files served from Zope3 resource directories.
+      
+      - Changed the condition checking for setting status of
+        HTTPResponse from to account for new-style classes.
+      
+      - The Wrapper_compare function from tp_compare to tp_richcompare.
+        Also another function Wrapper_richcompare is added.
+      
+      - The doc test has been slightly changed in ZPublisher to get
+        the error message extracted correctly.
 
+      - The changes made in Acquisition.c in Implicit Acquisition
+        comparison made avail to Explicit Acquisition comparison also.
+
       - zopedoctest no longer breaks if the URL contains more than one
         question mark. It broke even when the second question mark was
         correctly quoted.

Modified: Zope/trunk/lib/python/AccessControl/ImplC.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/ImplC.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/ImplC.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -15,21 +15,23 @@
 
 
 try:
-    from cAccessControl import rolesForPermissionOn, \
+    from AccessControl.cAccessControl import rolesForPermissionOn, \
          PermissionRole, imPermissionRole, _what_not_even_god_should_do, \
          RestrictedDTMLMixin, aq_validate, guarded_getattr, \
          setDefaultBehaviors
-    from cAccessControl import ZopeSecurityPolicy as cZopeSecurityPolicy
-    from cAccessControl import SecurityManager as cSecurityManager
+    from AccessControl.cAccessControl import ZopeSecurityPolicy \
+        as cZopeSecurityPolicy
+    from AccessControl.cAccessControl import SecurityManager as cSecurityManager
 except ImportError:
     import sys
     # make sure a partial import doesn't pollute sys.modules
     del sys.modules[__name__]
+    raise
+    
+from AccessControl.ImplPython import RestrictedDTML
+from AccessControl.ImplPython import SecurityManager, ZopeSecurityPolicy
 
 
-from ImplPython import RestrictedDTML, SecurityManager, ZopeSecurityPolicy
-
-
 class RestrictedDTML(RestrictedDTMLMixin, RestrictedDTML):
     """A mix-in for derivatives of DT_String.String that adds Zope security."""
 

Modified: Zope/trunk/lib/python/AccessControl/ImplPython.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/ImplPython.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/ImplPython.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -30,7 +30,7 @@
 except ImportError:
     _what_not_even_god_should_do = []
 
-from AccessControl import SecurityManagement
+from AccessControl.SecurityManagement import getSecurityManager
 from AccessControl import Unauthorized
 from AccessControl.interfaces import ISecurityPolicy
 from AccessControl.interfaces import ISecurityManager
@@ -721,7 +721,7 @@
     # See if we can get the value doing a filtered acquire.
     # aq_acquire will either return the same value as held by
     # v or it will return an Unauthorized raised by validate.
-    validate = SecurityManagement.getSecurityManager().validate
+    validate = getSecurityManager().validate
     aq_acquire(inst, name, aq_validate, validate)
     
     return v

Modified: Zope/trunk/lib/python/AccessControl/ZopeGuards.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/ZopeGuards.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/ZopeGuards.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -237,18 +237,18 @@
         return reduce(f, guarded_iter(seq), initial)
 safe_builtins['reduce'] = guarded_reduce
 
-def guarded_max(item, *items):
+def guarded_max(item, *items, **kw):
     if items:
         item = [item]
         item.extend(items)
-    return max(guarded_iter(item))
+    return max(guarded_iter(item), **kw)
 safe_builtins['max'] = guarded_max
 
-def guarded_min(item, *items):
+def guarded_min(item, *items, **kw):
     if items:
         item = [item]
         item.extend(items)
-    return min(guarded_iter(item))
+    return min(guarded_iter(item), **kw)
 safe_builtins['min'] = guarded_min
 
 def guarded_map(f, *seqs):
@@ -375,6 +375,17 @@
 
 safe_builtins['apply'] = builtin_guarded_apply
 
+# Similar to min and reduce, use guarded_iter on the sequence being
+# tested and apply the original function.
+if sys.version_info >= (2, 5):
+    def guarded_any(seq):
+        return any(guarded_iter(seq))
+    safe_builtins['any'] = guarded_any
+
+    def guarded_all(seq):
+        return all(guarded_iter(seq))
+    safe_builtins['all'] = guarded_all
+
 # This metaclass supplies the security declarations that allow all
 # attributes of a class and its instances to be read and written.
 def _metaclass(name, bases, dict):

Modified: Zope/trunk/lib/python/AccessControl/__init__.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/__init__.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/__init__.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -14,18 +14,18 @@
 from unauthorized import Unauthorized
 
 # This has to happen early so things get initialized properly
-from Implementation import setImplementation
+from AccessControl.Implementation import setImplementation
 
-from SecurityManagement import getSecurityManager, setSecurityPolicy
-from SecurityInfo import ClassSecurityInfo, ModuleSecurityInfo
-from SecurityInfo import ACCESS_PRIVATE
-from SecurityInfo import ACCESS_PUBLIC
-from SecurityInfo import ACCESS_NONE
-from SecurityInfo import secureModule, allow_module, allow_class
-from SimpleObjectPolicies import allow_type
-from ZopeGuards import full_write_guard, safe_builtins
+from AccessControl.SecurityManagement import getSecurityManager, setSecurityPolicy
+from AccessControl.SecurityInfo import ClassSecurityInfo, ModuleSecurityInfo
+from AccessControl.SecurityInfo import ACCESS_PRIVATE
+from AccessControl.SecurityInfo import ACCESS_PUBLIC
+from AccessControl.SecurityInfo import ACCESS_NONE
+from AccessControl.SecurityInfo import secureModule, allow_module, allow_class
+from AccessControl.SimpleObjectPolicies import allow_type
+from AccessControl.ZopeGuards import full_write_guard, safe_builtins
 
 ModuleSecurityInfo('AccessControl').declarePublic('getSecurityManager')
 
-import DTML
+from AccessControl import DTML
 del DTML

Modified: Zope/trunk/lib/python/AccessControl/cAccessControl.c
===================================================================
--- Zope/trunk/lib/python/AccessControl/cAccessControl.c	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/cAccessControl.c	2008-10-26 05:59:00 UTC (rev 92577)
@@ -2301,7 +2301,7 @@
 	/*| from logger_wrapper import warn
 	*/
 
-	IMPORT(module, "logger_wrapper");
+	IMPORT(module, "AccessControl.logger_wrapper");
 	GETATTR(module, warn);
 	Py_DECREF(module);
 	module = NULL;

Modified: Zope/trunk/lib/python/AccessControl/tests/actual_python.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/tests/actual_python.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/tests/actual_python.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -163,3 +163,14 @@
     x += 1
 f11()
 
+def f12():
+    assert all([True, True, True]) == True
+    assert all([True, False, True]) == False
+f12()
+
+def f13():
+    assert any([True, True, True]) == True
+    assert any([True, False, True]) == True
+    assert any([False, False, False]) == False
+f13()
+

Modified: Zope/trunk/lib/python/AccessControl/tests/testZopeGuards.py
===================================================================
--- Zope/trunk/lib/python/AccessControl/tests/testZopeGuards.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/AccessControl/tests/testZopeGuards.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -31,6 +31,9 @@
     get_iter, guarded_min, guarded_max, safe_builtins, guarded_enumerate, \
     guarded_sum, guarded_apply, guarded_map, guarded_zip
 
+if sys.version_info >= (2, 5):
+    from AccessControl.ZopeGuards import guarded_any, guarded_all
+
 try:
     __file__
 except NameError:
@@ -253,11 +256,26 @@
                           [1,2,3], [3,2,1])
         self.setSecurityManager(old)
 
+    if sys.version_info >= (2, 5):
+        def test_all_fails(self):
+            sm = SecurityManager(1) # rejects
+            old = self.setSecurityManager(sm)
+            self.assertRaises(Unauthorized, guarded_all, [True,True,False])
+            self.setSecurityManager(old)
+
+        def test_any_fails(self):
+            sm = SecurityManager(1) # rejects
+            old = self.setSecurityManager(sm)
+            self.assertRaises(Unauthorized, guarded_any, [True,True,False])
+            self.setSecurityManager(old)
+
     def test_min_fails(self):
         sm = SecurityManager(1) # rejects
         old = self.setSecurityManager(sm)
         self.assertRaises(Unauthorized, guarded_min, [1,2,3])
         self.assertRaises(Unauthorized, guarded_min, 1,2,3)
+        self.assertRaises(Unauthorized, guarded_min,
+                          [{'x':1},{'x':2}], operator.itemgetter('x'))
         self.setSecurityManager(old)
 
     def test_max_fails(self):
@@ -265,6 +283,8 @@
         old = self.setSecurityManager(sm)
         self.assertRaises(Unauthorized, guarded_max, [1,2,3])
         self.assertRaises(Unauthorized, guarded_max, 1,2,3)
+        self.assertRaises(Unauthorized, guarded_max, 
+                          [{'x':1},{'x':2}], operator.itemgetter('x'))
         self.setSecurityManager(old)
 
     def test_enumerate_fails(self):
@@ -295,11 +315,26 @@
                          [4,4,4])
         self.setSecurityManager(old)
 
+    if sys.version_info >= (2, 5):
+        def test_all_succeeds(self):
+            sm = SecurityManager() # accepts
+            old = self.setSecurityManager(sm)
+            self.assertEqual(guarded_all([True,True,False]), False)
+            self.setSecurityManager(old)
+
+        def test_any_succeeds(self):
+            sm = SecurityManager() # accepts
+            old = self.setSecurityManager(sm)
+            self.assertEquals(guarded_any([True,True,False]), True)
+            self.setSecurityManager(old)
+
     def test_min_succeeds(self):
         sm = SecurityManager() # accepts
         old = self.setSecurityManager(sm)
         self.assertEqual(guarded_min([1,2,3]), 1)
         self.assertEqual(guarded_min(1,2,3), 1)
+        self.assertEqual(guarded_min({'x':1},{'x':2}, 
+                                     key=operator.itemgetter('x')), {'x':1})
         self.setSecurityManager(old)
 
     def test_max_succeeds(self):
@@ -307,6 +342,8 @@
         old = self.setSecurityManager(sm)
         self.assertEqual(guarded_max([1,2,3]), 3)
         self.assertEqual(guarded_max(1,2,3), 3)
+        self.assertEqual(guarded_max({'x':1},{'x':2}, 
+                                     key=operator.itemgetter('x')), {'x':2})
         self.setSecurityManager(old)
 
     def test_enumerate_succeeds(self):

Modified: Zope/trunk/lib/python/Acquisition/_Acquisition.c
===================================================================
--- Zope/trunk/lib/python/Acquisition/_Acquisition.c	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Acquisition/_Acquisition.c	2008-10-26 05:59:00 UTC (rev 92577)
@@ -103,6 +103,32 @@
 
 #define Build Py_BuildValue
 
+/* For obscure reasons, we need to use tp_richcompare instead of tp_compare.
+ * The comparisons here all most naturally compute a cmp()-like result.
+ * This little helper turns that into a bool result for rich comparisons.
+ */
+static PyObject *
+diff_to_bool(int diff, int op)
+{
+	PyObject *result;
+	int istrue;
+
+	switch (op) {
+		case Py_EQ: istrue = diff == 0; break;
+		case Py_NE: istrue = diff != 0; break;
+		case Py_LE: istrue = diff <= 0; break;
+		case Py_GE: istrue = diff >= 0; break;
+		case Py_LT: istrue = diff < 0; break;
+		case Py_GT: istrue = diff > 0; break;
+		default:
+			assert(! "op unknown");
+			istrue = 0; /* To shut up compiler */
+	}
+	result = istrue ? Py_True : Py_False;
+	Py_INCREF(result);
+	return result;
+}
+
 /* Declarations for objects of type Wrapper */
 
 typedef struct {
@@ -759,6 +785,13 @@
 }
 
 static PyObject *
+Wrapper_richcompare(Wrapper *self, PyObject *w, int op)
+{
+  int diff = Wrapper_compare(self, w);
+  return diff_to_bool(diff, op);
+}
+
+static PyObject *
 Wrapper_repr(Wrapper *self)
 {
   PyObject *r;
@@ -1241,7 +1274,7 @@
   (printfunc)0,				/*tp_print*/
   (getattrfunc)0,			/*tp_getattr*/
   (setattrfunc)0,			/*tp_setattr*/
-  (cmpfunc)Wrapper_compare,    		/*tp_compare*/
+  (cmpfunc)0,	    			/*tp_compare*/
   (reprfunc)Wrapper_repr,      		/*tp_repr*/
   &Wrapper_as_number,			/*tp_as_number*/
   &Wrapper_as_sequence,			/*tp_as_sequence*/
@@ -1259,7 +1292,7 @@
   "Wrapper object for implicit acquisition", /* Documentation string */
   /* tp_traverse       */ (traverseproc)Wrapper_traverse,
   /* tp_clear          */ (inquiry)Wrapper_clear,
-  /* tp_richcompare    */ (richcmpfunc)0,
+  /* tp_richcompare    */ (richcmpfunc)Wrapper_richcompare,
   /* tp_weaklistoffset */ (long)0,
   /* tp_iter           */ (getiterfunc)0,
   /* tp_iternext       */ (iternextfunc)0,
@@ -1285,7 +1318,7 @@
   (printfunc)0,				/*tp_print*/
   (getattrfunc)0,			/*tp_getattr*/
   (setattrfunc)0,			/*tp_setattr*/
-  (cmpfunc)Wrapper_compare,    		/*tp_compare*/
+  (cmpfunc)0,    		/*tp_compare*/
   (reprfunc)Wrapper_repr,      		/*tp_repr*/
   &Wrapper_as_number,			/*tp_as_number*/
   &Wrapper_as_sequence,			/*tp_as_sequence*/
@@ -1303,7 +1336,7 @@
   "Wrapper object for implicit acquisition", /* Documentation string */
   /* tp_traverse       */ (traverseproc)Wrapper_traverse,
   /* tp_clear          */ (inquiry)Wrapper_clear,
-  /* tp_richcompare    */ (richcmpfunc)0,
+  /* tp_richcompare    */ (richcmpfunc)Wrapper_richcompare,
   /* tp_weaklistoffset */ (long)0,
   /* tp_iter           */ (getiterfunc)0,
   /* tp_iternext       */ (iternextfunc)0,

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_HTML.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_HTML.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_HTML.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -14,9 +14,9 @@
 
 $Id$"""
 
-from DT_String import String, FileMixin
-import DT_String, re
-from DT_Util import ParseError, str
+import re
+from DocumentTemplate.DT_String import String, FileMixin
+from DocumentTemplate.DT_Util import ParseError, str
 
 class dtml_re_class:
     """ This needs to be replaced before 2.4.  It's a hackaround. """
@@ -129,7 +129,7 @@
     def start(self, *args):
         return self._start
 
-class HTML(DT_String.String):
+class HTML(String):
     """HTML Document Templates
 
     HTML Document templates use HTML server-side-include syntax,

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_If.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_If.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_If.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -78,7 +78,7 @@
 __rcs_id__='$Id$'
 __version__='$Revision: 1.19 $'[11:-2]
 
-from DT_Util import ParseError, parse_params, name_param, str
+from DocumentTemplate.DT_Util import ParseError, parse_params, name_param, str
 
 class If:
     blockContinuations='else','elif'

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_In.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_In.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_In.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -333,14 +333,18 @@
 __version__='$Revision: 1.62 $'[11:-2]
 
 import sys
-from DT_Util import ParseError, parse_params, name_param, str, join_unicode
-from DT_Util import render_blocks, InstanceDict, ValidationError, Eval
-from DT_Util import simple_name, add_with_prefix
 import re
-from DT_InSV import sequence_variables, opt
-TupleType=type(())
-StringTypes = (type(''), type(u''))
 
+from DocumentTemplate.DT_Util import ParseError, parse_params, name_param
+from DocumentTemplate.DT_Util import str, join_unicode
+from DocumentTemplate.DT_Util import render_blocks, InstanceDict
+from DocumentTemplate.DT_Util import ValidationError, Eval
+from DocumentTemplate.DT_Util import simple_name, add_with_prefix
+from DocumentTemplate.DT_InSV import sequence_variables, opt
+
+TupleType = tuple
+StringTypes = (str, unicode)
+
 class InFactory:
     blockContinuations=('else',)
     name='in'

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_InSV.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_InSV.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_InSV.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -18,12 +18,13 @@
 
 from math import sqrt
 import re
-TupleType=type(())
+
 try:
     import Missing
     mv=Missing.Value
 except: mv=None
 
+TupleType = tuple
 
 class sequence_variables:
 

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Let.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Let.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Let.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -40,10 +40,11 @@
    as desired.
 '''
 
-from DT_Util import render_blocks, Eval, ParseError
-from DT_Util import str # Probably needed due to hysterical pickles.
 import re
 
+from DocumentTemplate.DT_Util import render_blocks, Eval, ParseError
+from DocumentTemplate.DT_Util import str # Probably needed due to
+                                         # hysterical pickles.
 
 class Let:
     blockContinuations=()

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Raise.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Raise.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Raise.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -26,8 +26,12 @@
 __rcs_id__='$Id$'
 __version__='$Revision: 1.13 $'[11:-2]
 
-from DT_Util import parse_params, name_param, render_blocks, str
+from zExceptions import upgradeException
+from DocumentTemplate.DT_Util import parse_params, name_param, render_blocks, str
 
+class InvalidErrorTypeExpression(Exception):
+    pass
+
 class Raise:
     blockContinuations=()
     name='raise'
@@ -44,15 +48,17 @@
         expr=self.expr
         if expr is None:
             t=self.__name__
-            if t[-5:]=='Error' and __builtins__.has_key(t):
-                t=__builtins__[t]
         else:
             try: t=expr.eval(md)
-            except: t='Invalid Error Type Expression'
+            except: t=InvalidErrorTypeExpression
 
         try: v=render_blocks(self.section,md)
         except: v='Invalid Error Value'
-
+        
+        # String Exceptions are deprecated on Python 2.5 and
+        # plain won't work at all on Python 2.6. So try to upgrade it
+        # to a real exception.
+        t, v = upgradeException(t, v)
         raise t, v
 
     __call__=render

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Return.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Return.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Return.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -12,7 +12,7 @@
 ##############################################################################
 __version__='$Revision: 1.9 $'[11:-2]
 
-from DT_Util import parse_params, name_param
+from DocumentTemplate.DT_Util import parse_params, name_param
 
 class ReturnTag:
     name='return'

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_String.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_String.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_String.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -16,9 +16,10 @@
 import thread
 import re
 
-from DT_Util import ParseError, InstanceDict, TemplateDict, render_blocks, str
-from DT_Var import Var, Call, Comment
-from DT_Return import ReturnTag, DTReturn
+from DocumentTemplate.DT_Util import ParseError, InstanceDict
+from DocumentTemplate.DT_Util import TemplateDict, render_blocks, str
+from DocumentTemplate.DT_Var import Var, Call, Comment
+from DocumentTemplate.DT_Return import ReturnTag, DTReturn
 
 _marker = []  # Create a new marker object.
 

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Try.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Try.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Try.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -13,9 +13,9 @@
 
 import  sys, traceback
 from cStringIO import StringIO
-from DT_Util import ParseError, parse_params, render_blocks
-from DT_Util import namespace, InstanceDict
-from DT_Return import DTReturn
+from DocumentTemplate.DT_Util import ParseError, parse_params, render_blocks
+from DocumentTemplate.DT_Util import namespace, InstanceDict
+from DocumentTemplate.DT_Return import DTReturn
 
 class Try:
     """Zope DTML Exception handling

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_UI.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_UI.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_UI.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -15,7 +15,7 @@
 $Id$'''
 __version__='$Revision: 1.15 $'[11:-2]
 
-from DT_HTML import HTML
+from DocumentTemplate.DT_HTML import HTML
 
 FactoryDefaultString="Factory Default"
 

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Util.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Util.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Util.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -16,12 +16,16 @@
 
 import re
 
-from html_quote import html_quote, ustr # for import by other modules, dont remove!
+# for import by other modules, dont remove!
+from DocumentTemplate.html_quote import html_quote, ustr
+
+from DocumentTemplate.cDocumentTemplate import InstanceDict, TemplateDict
+from DocumentTemplate.cDocumentTemplate import render_blocks, safe_callable
+from DocumentTemplate.cDocumentTemplate import join_unicode
+
 from RestrictedPython.Guards import safe_builtins
 from RestrictedPython.Utilities import utility_builtins
 from RestrictedPython.Eval import RestrictionCapableEval
-from cDocumentTemplate import InstanceDict, TemplateDict, \
-         render_blocks, safe_callable, join_unicode
 
 test = utility_builtins['test'] # for backwards compatibility, dont remove!
 
@@ -29,7 +33,9 @@
 
 str=__builtins__['str'] # Waaaaa, waaaaaaaa needed for pickling waaaaa
 
-ParseError='Document Template Parse Error'
+class ParseError(Exception):
+    """Document Template Parse Error"""
+
 from zExceptions import Unauthorized as ValidationError
 
 def int_param(params,md,name,default=0, st=type('')):
@@ -235,37 +241,37 @@
 
         if v[:1]=='"' and v[-1:]=='"' and len(v) > 1: # expr shorthand
             if used(attr):
-                raise ParseError, ('%s and expr given' % attr, tag)
+                raise ParseError('%s and expr given' % attr, tag)
             if expr:
                 if used('expr'):
-                    raise ParseError, ('two exprs given', tag)
+                    raise ParseError('two exprs given', tag)
                 v=v[1:-1]
                 try: expr=Eval(v)
                 except SyntaxError, v:
-                    raise ParseError, (
+                    raise ParseError(
                         '<strong>Expression (Python) Syntax error</strong>:'
                         '\n<pre>\n%s\n</pre>\n' % v[0],
                         tag)
                 return v, expr
-            else: raise ParseError, (
+            else: raise ParseError(
                 'The "..." shorthand for expr was used in a tag '
                 'that doesn\'t support expr attributes.',
                 tag)
 
         else: # name shorthand
             if used(attr):
-                raise ParseError, ('Two %s values were given' % attr, tag)
+                raise ParseError('Two %s values were given' % attr, tag)
             if expr:
                 if used('expr'):
                     # raise 'Waaaaaa', 'waaa'
-                    raise ParseError, ('%s and expr given' % attr, tag)
+                    raise ParseError('%s and expr given' % attr, tag)
                 return params[''],None
             return params['']
 
     elif used(attr):
         if expr:
             if used('expr'):
-                raise ParseError, ('%s and expr given' % attr, tag)
+                raise ParseError('%s and expr given' % attr, tag)
             return params[attr],None
         return params[attr]
     elif expr and used('expr'):
@@ -273,7 +279,7 @@
         expr=Eval(name)
         return name, expr
 
-    raise ParseError, ('No %s given' % attr, tag)
+    raise ParseError('No %s given' % attr, tag)
 
 Expr_doc="""
 
@@ -386,11 +392,11 @@
         l=len(mo_unp.group(1))
         if result:
             if parms.has_key(name):
-                if parms[name] is None: raise ParseError, (
+                if parms[name] is None: raise ParseError(
                     'Attribute %s requires a value' % name, tag)
 
                 result[name]=parms[name]
-            else: raise ParseError, (
+            else: raise ParseError(
                 'Invalid attribute name, "%s"' % name, tag)
         else:
             result['']=name
@@ -398,22 +404,22 @@
     elif mo_unq:
         name=mo_unq.group(2)
         l=len(mo_unq.group(1))
-        if result: raise ParseError, (
+        if result: raise ParseError(
             'Invalid attribute name, "%s"' % name, tag)
         else: result['']=name
         return parse_params(text[l:],result,**parms)
     else:
         if not text or not text.strip(): return result
-        raise ParseError, ('invalid parameter: "%s"' % text, tag)
+        raise ParseError('invalid parameter: "%s"' % text, tag)
 
     if not parms.has_key(name):
-        raise ParseError, (
+        raise ParseError(
             'Invalid attribute name, "%s"' % name, tag)
 
     if result.has_key(name):
         p=parms[name]
         if type(p) is not ListType or p:
-            raise ParseError, (
+            raise ParseError(
                 'Duplicate values for attribute "%s"' % name, tag)
 
     result[name]=value

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_Var.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_Var.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_Var.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -151,14 +151,18 @@
 
 
 ''' # '
+
 __rcs_id__='$Id$'
 __version__='$Revision: 1.60 $'[11:-2]
 
+import string, re, sys
 from cgi import escape
-import string, re,  sys
 from urllib import quote, quote_plus, unquote, unquote_plus
-from DT_Util import parse_params, name_param, str, ustr
-from html_quote import html_quote # for import by other modules, dont remove!
+
+# for import by other modules, dont remove!
+from DocumentTemplate.html_quote import html_quote
+from DocumentTemplate.DT_Util import parse_params, name_param, str, ustr
+
 from Acquisition import aq_base
 from ZPublisher.TaintedString import TaintedString
 from zope.structuredtext.html import HTMLWithImages, HTML

Modified: Zope/trunk/lib/python/DocumentTemplate/DT_With.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DT_With.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DT_With.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -36,8 +36,10 @@
 __rcs_id__='$Id$'
 __version__='$Revision: 1.15 $'[11:-2]
 
-from DT_Util import parse_params, name_param, InstanceDict, render_blocks, str
-from DT_Util import TemplateDict
+from DocumentTemplate.DT_Util import parse_params, name_param
+from DocumentTemplate.DT_Util import InstanceDict, render_blocks, str
+from DocumentTemplate.DT_Util import TemplateDict
+
 class With:
     blockContinuations=()
     name='with'

Deleted: Zope/trunk/lib/python/DocumentTemplate/DocumentTemplate.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/DocumentTemplate.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/DocumentTemplate.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -1,114 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 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
-#
-##############################################################################
-'''Document templates with fill-in fields
-
-Document templates provide for creation of textual documents, such as
-HTML pages, from template source by inserting data from python objects
-and name-spaces.
-
-When a document template is created, a collection of default values to
-be inserted may be specified with a mapping object and with keyword
-arguments.
-
-A document templated may be called to create a document with values
-inserted.  When called, an instance, a mapping object, and keyword
-arguments may be specified to provide values to be inserted.  If an
-instance is provided, the document template will try to look up values
-in the instance using getattr, so inheritence of values is supported.
-If an inserted value is a function, method, or class, then an attempt
-will be made to call the object to obtain values.  This allows
-instance methods to be included in documents.
-
-Document templates masquerade as functions, so the python object
-publisher (Bobo) will call templates that are stored as instances of
-published objects. Bobo will pass the object the template was found in
-and the HTTP request object.
-
-Two source formats are supported:
-
-   Extended Python format strings (EPFS) --
-      This format is based on the insertion by name format strings
-      of python with additional format characters, '[' and ']' to
-      indicate block boundaries.  In addition, parameters may be
-      used within formats to control how insertion is done.
-
-      For example:
-
-         %%(date fmt=DayOfWeek upper)s
-
-      causes the contents of variable 'date' to be inserted using
-      custom format 'DayOfWeek' and with all lower case letters
-      converted to upper case.
-
-   HTML --
-      This format uses HTML server-side-include syntax with
-      commands for inserting text. Parameters may be included to
-      customize the operation of a command.
-
-      For example:
-
-         <!--#var total fmt=12.2f-->
-
-      is used to insert the variable 'total' with the C format
-      '12.2f'.
-
-Document templates support conditional and sequence insertion
-
-    Document templates extend python string substitition rules with a
-    mechanism that allows conditional insertion of template text and that
-    allows sequences to be inserted with element-wise insertion of
-    template text.
-
-Access Control
-
-    Document templates provide a basic level of access control by
-    preventing access to names beginning with an underscore.
-    Additional control may be provided by providing document templates
-    with a 'guarded_getattr' and 'guarded_getitem' method.  This would
-    typically be done by subclassing one or more of the DocumentTemplate
-    classes.
-
-    If provided, the the 'guarded_getattr' method will be called when
-    objects are accessed as instance attributes or when they are
-    accessed through keyed access in an expression.
-
-Document Templates may be created 4 ways:
-
-    DocumentTemplate.String -- Creates a document templated from a
-        string using an extended form of python string formatting.
-
-    DocumentTemplate.File -- Creates a document templated bound to a
-        named file using an extended form of python string formatting.
-        If the object is pickled, the file name, rather than the file
-        contents is pickled.  When the object is unpickled, then the
-        file will be re-read to obtain the string.  Note that the file
-        will not be read until the document template is used the first
-        time.
-
-    DocumentTemplate.HTML -- Creates a document templated from a
-        string using HTML server-side-include rather than
-        python-format-string syntax.
-
-    DocumentTemplate.HTMLFile -- Creates an HTML document template
-        from a named file.
-
-'''
-
-
-__version__='$Revision: 1.14 $'[11:-2]
-
-ParseError='Document Template Parse Error'
-
-from DT_String import String, File
-from DT_HTML import HTML, HTMLFile, HTMLDefault
-# import DT_UI # Install HTML editing

Modified: Zope/trunk/lib/python/DocumentTemplate/VSEval.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/VSEval.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/VSEval.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -1,6 +1,6 @@
 # alias module for backwards compatibility
 
-from DT_Util import Eval
+from DocumentTemplate.DT_Util import Eval
 
 def careful_mul(env, *factors):
     r = 1

Copied: Zope/trunk/lib/python/DocumentTemplate/_DocumentTemplate.py (from rev 92571, Zope/branches/gsoc-python-2.5/lib/python/DocumentTemplate/_DocumentTemplate.py)
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/_DocumentTemplate.py	                        (rev 0)
+++ Zope/trunk/lib/python/DocumentTemplate/_DocumentTemplate.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -0,0 +1,114 @@
+##############################################################################
+#
+# Copyright (c) 2002 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
+#
+##############################################################################
+'''Document templates with fill-in fields
+
+Document templates provide for creation of textual documents, such as
+HTML pages, from template source by inserting data from python objects
+and name-spaces.
+
+When a document template is created, a collection of default values to
+be inserted may be specified with a mapping object and with keyword
+arguments.
+
+A document templated may be called to create a document with values
+inserted.  When called, an instance, a mapping object, and keyword
+arguments may be specified to provide values to be inserted.  If an
+instance is provided, the document template will try to look up values
+in the instance using getattr, so inheritence of values is supported.
+If an inserted value is a function, method, or class, then an attempt
+will be made to call the object to obtain values.  This allows
+instance methods to be included in documents.
+
+Document templates masquerade as functions, so the python object
+publisher (Bobo) will call templates that are stored as instances of
+published objects. Bobo will pass the object the template was found in
+and the HTTP request object.
+
+Two source formats are supported:
+
+   Extended Python format strings (EPFS) --
+      This format is based on the insertion by name format strings
+      of python with additional format characters, '[' and ']' to
+      indicate block boundaries.  In addition, parameters may be
+      used within formats to control how insertion is done.
+
+      For example:
+
+         %%(date fmt=DayOfWeek upper)s
+
+      causes the contents of variable 'date' to be inserted using
+      custom format 'DayOfWeek' and with all lower case letters
+      converted to upper case.
+
+   HTML --
+      This format uses HTML server-side-include syntax with
+      commands for inserting text. Parameters may be included to
+      customize the operation of a command.
+
+      For example:
+
+         <!--#var total fmt=12.2f-->
+
+      is used to insert the variable 'total' with the C format
+      '12.2f'.
+
+Document templates support conditional and sequence insertion
+
+    Document templates extend python string substitition rules with a
+    mechanism that allows conditional insertion of template text and that
+    allows sequences to be inserted with element-wise insertion of
+    template text.
+
+Access Control
+
+    Document templates provide a basic level of access control by
+    preventing access to names beginning with an underscore.
+    Additional control may be provided by providing document templates
+    with a 'guarded_getattr' and 'guarded_getitem' method.  This would
+    typically be done by subclassing one or more of the DocumentTemplate
+    classes.
+
+    If provided, the the 'guarded_getattr' method will be called when
+    objects are accessed as instance attributes or when they are
+    accessed through keyed access in an expression.
+
+Document Templates may be created 4 ways:
+
+    DocumentTemplate.String -- Creates a document templated from a
+        string using an extended form of python string formatting.
+
+    DocumentTemplate.File -- Creates a document templated bound to a
+        named file using an extended form of python string formatting.
+        If the object is pickled, the file name, rather than the file
+        contents is pickled.  When the object is unpickled, then the
+        file will be re-read to obtain the string.  Note that the file
+        will not be read until the document template is used the first
+        time.
+
+    DocumentTemplate.HTML -- Creates a document templated from a
+        string using HTML server-side-include rather than
+        python-format-string syntax.
+
+    DocumentTemplate.HTMLFile -- Creates an HTML document template
+        from a named file.
+
+'''
+
+
+__version__='$Revision: 1.14 $'[11:-2]
+
+from DocumentTemplate.DT_Raise import ParseError
+from DocumentTemplate.DT_String import String, File
+from DocumentTemplate.DT_HTML import HTML, HTMLFile, HTMLDefault
+
+# import DT_UI # Install HTML editing

Modified: Zope/trunk/lib/python/DocumentTemplate/__init__.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/__init__.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/__init__.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -18,4 +18,5 @@
 $Id$'''
 __version__='$Revision: 1.18 $'[11:-2]
 
-from DocumentTemplate import String, File, HTML, HTMLDefault, HTMLFile
+from DocumentTemplate.DT_String import String, File
+from DocumentTemplate.DT_HTML import HTML, HTMLDefault, HTMLFile

Modified: Zope/trunk/lib/python/DocumentTemplate/cDocumentTemplate.c
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/cDocumentTemplate.c	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/cDocumentTemplate.c	2008-10-26 05:59:00 UTC (rev 92577)
@@ -972,7 +972,7 @@
 
   DictInstanceType.ob_type=&PyType_Type;
 
-  UNLESS (html_quote = PyImport_ImportModule("html_quote")) return;
+  UNLESS (html_quote = PyImport_ImportModule("DocumentTemplate.html_quote")) return;
   ASSIGN(ustr, PyObject_GetAttrString(html_quote, "ustr"));
   UNLESS (ustr) return;
   ASSIGN(html_quote, PyObject_GetAttrString(html_quote, "html_quote"));

Modified: Zope/trunk/lib/python/DocumentTemplate/html_quote.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/html_quote.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/html_quote.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -1,7 +1,7 @@
 # split off into its own module for aliasing without circrefs
 
 from cgi import escape
-from ustr import ustr
+from DocumentTemplate.ustr import ustr
 
 def html_quote(v, name='(Unknown name)', md={}):
     return escape(ustr(v), 1)

Modified: Zope/trunk/lib/python/DocumentTemplate/pDocumentTemplate.py
===================================================================
--- Zope/trunk/lib/python/DocumentTemplate/pDocumentTemplate.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/DocumentTemplate/pDocumentTemplate.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -20,7 +20,7 @@
 
 import sys, types
 from types import StringType, UnicodeType, TupleType
-from ustr import ustr
+from DocumentTemplate.ustr import ustr
 
 import warnings
 warnings.warn('pDocumentTemplate is not longer in active use. '

Modified: Zope/trunk/lib/python/OFS/CopySupport.py
===================================================================
--- Zope/trunk/lib/python/OFS/CopySupport.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/OFS/CopySupport.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -48,7 +48,7 @@
 from OFS.interfaces import ICopySource
 
 
-CopyError='Copy Error'
+class CopyError(Exception): pass
 
 copy_re = re.compile('^copy([0-9]*)_of_(.*)')
 

Modified: Zope/trunk/lib/python/OFS/SimpleItem.py
===================================================================
--- Zope/trunk/lib/python/OFS/SimpleItem.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/OFS/SimpleItem.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -36,7 +36,7 @@
 from DocumentTemplate.ustr import ustr
 from ExtensionClass import Base
 from webdav.Resource import Resource
-from zExceptions import Redirect
+from zExceptions import Redirect, upgradeException
 from zExceptions.ExceptionFormatter import format_exception
 from zope.interface import implements
 
@@ -181,16 +181,24 @@
             elif type(tb) is type('') and not error_tb:
                 error_tb = tb
 
-            # turn error_type into a string
-            if hasattr(error_type, '__name__'):
-                error_type=error_type.__name__
+            # warn if error_type is a string
+            error_name = 'Unknown'
+            if isinstance(error_type, basestring):
+                # String Exceptions are deprecated on Python 2.5 and
+                # plain won't work at all on Python 2.6. So try to upgrade it
+                # to a real exception.
+                error_name = error_type
+                error_type, error_value = upgradeException(error_type, error_value)
+            else:
+                if hasattr(error_type, '__name__'):
+                    error_name = error_type.__name__
 
             if hasattr(self, '_v_eek'):
                 # Stop if there is recursion.
                 raise error_type, error_value, tb
             self._v_eek=1
 
-            if str(error_type).lower() in ('redirect',):
+            if error_name.lower() in ('redirect',):
                 raise error_type, error_value, tb
 
             if not error_message:
@@ -216,7 +224,10 @@
                 else:
                     client = aq_parent(client)
                     s=getattr(client, 'standard_error_message')
-                kwargs = {'error_type': error_type,
+                # For backward compatibility, we pass 'error_name' as
+                # 'error_type' here as historically this has always
+                # been a string.
+                kwargs = {'error_type': error_name,
                           'error_value': error_value,
                           'error_tb': error_tb,
                           'error_traceback': error_tb,

Modified: Zope/trunk/lib/python/OFS/tests/testCopySupport.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testCopySupport.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/OFS/tests/testCopySupport.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -347,7 +347,7 @@
             if ce_regex is not None:
 
                 pattern = re.compile( ce_regex, re.DOTALL )
-                if pattern.search( e ) is None:
+                if pattern.search( e.args[0] ) is None:
                     self.fail( "Paste failed; didn't match pattern:\n%s" % e )
 
             else:

Modified: Zope/trunk/lib/python/Products/Five/testbrowser.py
===================================================================
--- Zope/trunk/lib/python/Products/Five/testbrowser.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Products/Five/testbrowser.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -18,6 +18,8 @@
 $Id$
 """
 
+import sys
+import socket
 import urllib2
 
 import mechanize
@@ -29,7 +31,7 @@
 
 class PublisherConnection(testing.PublisherConnection):
 
-    def __init__(self, host):
+    def __init__(self, host, timeout=None):
         from Testing.ZopeTestCase.zopedoctest.functional import http
         self.caller = http
         self.host = host
@@ -76,6 +78,10 @@
     def http_open(self, req):
         """Open an HTTP connection having a ``urllib2`` request."""
         # Here we connect to the publisher.
+        if sys.version_info > (2, 6) and not hasattr(req, 'timeout'):
+            # Workaround mechanize incompatibility with Python
+            # 2.6. See: LP #280334
+            req.timeout = socket._GLOBAL_DEFAULT_TIMEOUT
         return self.do_open(PublisherConnection, req)
 
 

Modified: Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py
===================================================================
--- Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Products/PythonScripts/tests/testPythonScript.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -10,7 +10,7 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-import os, unittest, warnings
+import os, sys, unittest, warnings
 
 from Products.PythonScripts.PythonScript import PythonScript
 from AccessControl.SecurityManagement import newSecurityManager
@@ -297,13 +297,19 @@
         f = self._filePS('class.__name__')
         self.assertEqual(f(), ("'foo'>", "'string'"))
 
-    def test_filepath(self):
-        # This test is meant to raise a deprecation warning.
-        # It used to fail mysteriously instead.
-        self._trap_warning_output()
-        f = self._filePS('filepath')
-        self.assertEqual(f(), [0])
-        self._free_warning_output()
+    if sys.version_info < (2, 6):
+        def test_filepath(self):
+            # This test is meant to raise a deprecation warning.
+            # It used to fail mysteriously instead.
+            self._trap_warning_output()
+            f = self._filePS('filepath')
+            self.assertEqual(f(), [0])
+            self._free_warning_output()
+    else:
+        def test_filepath(self):
+            # On Python 2.6, this now raises a TypeError.
+            f = self._filePS('filepath')
+            self.assertRaises(TypeError, f)
 
 class PythonScriptInterfaceConformanceTests(unittest.TestCase):
 

Modified: Zope/trunk/lib/python/Shared/DC/ZRDB/sqlvar.py
===================================================================
--- Zope/trunk/lib/python/Shared/DC/ZRDB/sqlvar.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Shared/DC/ZRDB/sqlvar.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -61,10 +61,11 @@
 
 from DocumentTemplate.DT_Util import ParseError, parse_params, name_param
 from string import find, split, join, atoi, atof
-StringType=type('')
 
-str=__builtins__['str']
+StringType = str
 
+str = __builtins__['str']
+
 class SQLVar:
     name='sqlvar'
 
@@ -78,10 +79,10 @@
 
         self.args=args
         if not args.has_key('type'):
-            raise ParseError, ('the type attribute is required', 'dtvar')
+            raise ParseError('the type attribute is required', 'dtvar')
         t=args['type']
         if not valid_type(t):
-            raise ParseError, ('invalid type, %s' % t, 'dtvar')
+            raise ParseError('invalid type, %s' % t, 'dtvar')
 
     def render(self, md):
         name=self.__name__

Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -217,7 +217,7 @@
             # It has already been determined.
             return
 
-        if (isinstance(status, types.ClassType)
+        if (isinstance(status, (type, types.ClassType))
          and issubclass(status, Exception)):
             status = status.__name__
 

Modified: Zope/trunk/lib/python/ZPublisher/tests/testPublish.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testPublish.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/ZPublisher/tests/testPublish.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -29,7 +29,8 @@
             exception = exceptions[0]
             exceptions.remove(exception)
             exceptionShortName = exception.__name__ # KISS
-            self.append('raising %s from %s' % (exceptionShortName, context))
+            exceptionShortName = exceptionShortName.split("'")[0]
+	    self.append('raising %s from %s' % (exceptionShortName, context))
             raise exception
 
 

Modified: Zope/trunk/lib/python/ZServer/HTTPServer.py
===================================================================
--- Zope/trunk/lib/python/ZServer/HTTPServer.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/ZServer/HTTPServer.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -45,7 +45,8 @@
 from ZPublisher.HTTPRequest import HTTPRequest
 from App.config import getConfiguration
 
-from medusa.http_server import http_server,get_header, http_channel, VERSION_STRING
+from medusa.http_server import http_server, get_header
+from medusa.http_server import fifo, http_channel, VERSION_STRING
 import asyncore
 from medusa import counter, producers
 from medusa.test import  max_sockets
@@ -334,6 +335,18 @@
 
     def __init__(self, server, conn, addr):
         http_channel.__init__(self, server, conn, addr)
+        if isinstance(self.producer_fifo, fifo):
+            self.producer_fifo_push = self.producer_fifo.push
+            self.producer_fifo_first = self.producer_fifo.first
+            self.producer_fifo_pop = self.producer_fifo.pop
+        else:
+            self.producer_fifo_push = self.producer_fifo.append
+            def first():
+                return self.producer_fifo[0]
+            self.producer_fifo_first = first
+            def pop():
+                del self.producer_fifo[0]
+            self.producer_fifo_pop = pop
         requestCloseOnExec(conn)
         self.queue=[]
         self.working=0
@@ -345,7 +358,7 @@
         # producers by default
         if self.closed:
             return
-        self.producer_fifo.push(producer)
+        self.producer_fifo_push(producer)
         if send: self.initiate_send()
 
     push_with_producer=push
@@ -381,10 +394,10 @@
             self.current_request.channel = None # break circ refs
             self.current_request=None
         while self.producer_fifo:
-            p=self.producer_fifo.first()
+            p=self.producer_fifo_first()
             if p is not None and not isinstance(p, basestring):
                 p.more() # free up resources held by producer
-            self.producer_fifo.pop()
+            self.producer_fifo_pop()
         dispatcher.close(self)
 
     def done(self):

Modified: Zope/trunk/lib/python/ZServer/medusa/http_server.py
===================================================================
--- Zope/trunk/lib/python/ZServer/medusa/http_server.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/ZServer/medusa/http_server.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -528,25 +528,25 @@
                     # no handlers, so complain
             r.error (404)
             
-    def writable (self):
-            # this is just the normal async_chat 'writable', here for comparison
-        return self.ac_out_buffer or len(self.producer_fifo)
+    #def writable (self):
+    #        # this is just the normal async_chat 'writable', here for comparison
+    #    return self.ac_out_buffer or len(self.producer_fifo)
         
-    def writable_for_proxy (self):
-            # this version of writable supports the idea of a 'stalled' producer
-            # [i.e., it's not ready to produce any output yet] This is needed by
-            # the proxy, which will be waiting for the magic combination of
-            # 1) hostname resolved
-            # 2) connection made
-            # 3) data available.
-        if self.ac_out_buffer:
-            return 1
-        elif len(self.producer_fifo):
-            p = self.producer_fifo.first()
-            if hasattr (p, 'stalled'):
-                return not p.stalled()
-            else:
-                return 1
+    #def writable_for_proxy (self):
+    #        # this version of writable supports the idea of a 'stalled' producer
+    #        # [i.e., it's not ready to produce any output yet] This is needed by
+    #        # the proxy, which will be waiting for the magic combination of
+    #        # 1) hostname resolved
+    #        # 2) connection made
+    #        # 3) data available.
+    #    if self.ac_out_buffer:
+    #        return 1
+    #    elif len(self.producer_fifo):
+    #        p = self.producer_fifo.first()
+    #        if hasattr (p, 'stalled'):
+    #            return not p.stalled()
+    #        else:
+    #            return 1
                 
                 # ===========================================================================
                 #						 HTTP Server Object

Modified: Zope/trunk/lib/python/Zope2/App/startup.py
===================================================================
--- Zope/trunk/lib/python/Zope2/App/startup.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Zope2/App/startup.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -207,8 +207,9 @@
             else:
                 error_log_url = log.raising((t, v, traceback))
 
-            if (getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
-                !='text/html'):
+            if (REQUEST is None or 
+                (getattr(REQUEST.get('RESPONSE', None), '_error_format', '')
+                 != 'text/html')):
                 raise t, v, traceback
 
             # Lookup a view for the exception and render it, then

Modified: Zope/trunk/lib/python/Zope2/App/tests/testExceptionHook.py
===================================================================
--- Zope/trunk/lib/python/Zope2/App/tests/testExceptionHook.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/Zope2/App/tests/testExceptionHook.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -118,12 +118,20 @@
     def testStringException1(self):
         def f():
             raise 'unauthorized', 'x'
-        self.assertRaises('unauthorized', self.call, None, None, f)
+        if sys.version_info < (2, 6):
+            self.assertRaises('unauthorized', self.call, None, None, f)
+        else:
+            # Raising a string exception causes a TypeError on Python 2.6
+            self.assertRaises(TypeError, self.call, None, None, f)
 
     def testStringException2(self):
         def f():
             raise 'redirect', 'x'
-        self.assertRaises('redirect', self.call, None, None, f)
+        if sys.version_info < (2, 6):
+            self.assertRaises('redirect', self.call, None, None, f)
+        else:
+            # Raising a string exception causes a TypeError on Python 2.6
+            self.assertRaises(TypeError, self.call, None, None, f)
 
     def testSystemExit(self):
         def f():

Modified: Zope/trunk/lib/python/zExceptions/__init__.py
===================================================================
--- Zope/trunk/lib/python/zExceptions/__init__.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/lib/python/zExceptions/__init__.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -18,12 +18,13 @@
 $Id$
 """
 
-from unauthorized import Unauthorized
+import warnings
 
 from zope.interface import implements
 from zope.interface.common.interfaces import IException
 from zope.publisher.interfaces import INotFound
 from zope.security.interfaces import IForbidden
+from zExceptions.unauthorized import Unauthorized
 
 class BadRequest(Exception):
     implements(IException)
@@ -42,3 +43,29 @@
 
 class Redirect(Exception):
     pass
+
+def upgradeException(t, v):
+    # If a string exception is found, convert it to an equivalent
+    # exception defined either in builtins or zExceptions. If none of
+    # that works, tehn convert it to an InternalError and keep the
+    # original exception name as part of the exception value.
+    import zExceptions
+
+    if not isinstance(t, basestring):
+        return t, v
+
+    warnings.warn('String exceptions are deprecated starting '
+                  'with Python 2.5 and will be removed in a '
+                  'future release', DeprecationWarning, stacklevel=2)
+
+    n = None
+    if __builtins__.has_key(t):
+        n = __builtins__[t]
+    elif hasattr(zExceptions, t):
+        n = getattr(zExceptions, t)
+    if n is not None and issubclass(n, Exception):
+        t = n
+    else:
+        v = t, v
+        t = InternalError
+    return t, v

Modified: Zope/trunk/utilities/mkzopeinstance.py
===================================================================
--- Zope/trunk/utilities/mkzopeinstance.py	2008-10-26 05:57:34 UTC (rev 92576)
+++ Zope/trunk/utilities/mkzopeinstance.py	2008-10-26 05:59:00 UTC (rev 92577)
@@ -167,10 +167,10 @@
 
 def write_inituser(fn, user, password):
     import binascii
-    import sha
+    import hashlib
     fp = open(fn, "w")
-    pw = binascii.b2a_base64(sha.new(password).digest())[:-1]
-    fp.write('%s:{SHA}%s\n' % (user, pw))
+    pw = binascii.b2a_base64(hashlib.sha256(password).digest())[:-1]
+    fp.write('%s:{SHA256}%s\n' % (user, pw))
     fp.close()
     os.chmod(fn, 0644)
 



More information about the Checkins mailing list