[Checkins] SVN: Sandbox/malthe/chameleon.core/ Made error handler compatible with Python 2.4.

Malthe Borch mborch at gmail.com
Sat Nov 15 10:29:45 EST 2008


Log message for revision 92977:
  Made error handler compatible with Python 2.4.

Changed:
  U   Sandbox/malthe/chameleon.core/CHANGES.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/template.txt
  U   Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py

-=-
Modified: Sandbox/malthe/chameleon.core/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-15 14:50:22 UTC (rev 92976)
+++ Sandbox/malthe/chameleon.core/CHANGES.txt	2008-11-15 15:29:45 UTC (rev 92977)
@@ -4,6 +4,8 @@
 HEAD
 ~~~~
 
+- Made error handler compatible with Python 2.4 [malthe]
+
 - Maintain symbol mappings for joined expressions. [malthe]
 
 1.0b7 (released 15/11/2008)

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/template.txt
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/template.txt	2008-11-15 14:50:22 UTC (rev 92976)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/template.txt	2008-11-15 15:29:45 UTC (rev 92977)
@@ -126,6 +126,7 @@
 
   >>> class CustomException(Exception):
   ...     def __init__(self, msg):
+  ...         Exception.__init__(self, msg)
   ...         self.msg = msg
   
   >>> def dummy():
@@ -136,4 +137,3 @@
   ... except CustomException, exc:
   ...    print exc.msg
   This is a custom error message.
-

Modified: Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py
===================================================================
--- Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py	2008-11-15 14:50:22 UTC (rev 92976)
+++ Sandbox/malthe/chameleon.core/src/chameleon/core/utils.py	2008-11-15 15:29:45 UTC (rev 92977)
@@ -9,6 +9,8 @@
 import htmlentitydefs
 import re, string
 
+types = sys.modules['types']
+
 from UserDict import UserDict
 
 # check if we're able to coerce unicode to str
@@ -298,15 +300,20 @@
         ) % (annotation, description, "\n".join(formatted_arguments))    
 
     __dict__ = exc.__dict__
+    __name__ = cls.__name__
+    
     error_string = str(exc)
-    
+        
     if issubclass(cls, Exception):
         class RuntimeError(cls):
             def __str__(self):
                 return "%s\n%s: %s" % (
-                    error_msg, cls.__name__, error_string)
+                    error_msg, __name__, error_string)
 
-        exc = RuntimeError.__new__(RuntimeError)
-        exc.__dict__.update(__dict__)            
+        if isinstance(cls, types.TypeType):
+            exc = RuntimeError.__new__(RuntimeError)
+            exc.__dict__.update(__dict__)
+        else:
+            cls = RuntimeError
             
     raise cls, exc, tb



More information about the Checkins mailing list