opental-checkins
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OpenTAL-checkins] opental OpenPT/OpenPTBase.py OpenPT/Zpax.py pax...


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental OpenPT/OpenPTBase.py OpenPT/Zpax.py pax...
Date: Fri, 25 Apr 2003 12:04:04 -0400

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/04/25 12:04:04

Modified files:
        OpenPT         : OpenPTBase.py Zpax.py 
        pax            : core.py paxtransform.py textpaxparser.py 

Log message:
        misc rendering glitches I fixed last week and forgot to commit (hides 
head in sand)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/OpenPTBase.py.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/Zpax.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/pax/core.py.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/pax/paxtransform.py.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/pax/textpaxparser.py.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: opental/OpenPT/OpenPTBase.py
diff -u opental/OpenPT/OpenPTBase.py:1.10 opental/OpenPT/OpenPTBase.py:1.11
--- opental/OpenPT/OpenPTBase.py:1.10   Sun Apr 13 09:03:15 2003
+++ opental/OpenPT/OpenPTBase.py        Fri Apr 25 12:04:04 2003
@@ -15,7 +15,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.10 $'[11:-2]
+__version__='$Revision: 1.11 $'[11:-2]
 
 # ugh, this import list needs to be cleaned up
 import OpenTAL, pax, PTmetal_handler, pax.paxtransform, Zpax
@@ -196,6 +196,7 @@
         self.forced = encoding
 
     def encode(self, text):
+        __traceback_info__ = repr(text)
         if self.forced is not None:
             try:
                 return text.encode(self.forced), self.forced
@@ -538,7 +539,8 @@
             # now run the template
             #result = pax.XML(tr_engine.transform(self.paxtree(), context),
             #                     root_ns_map, self.encoding)
-            result = tr_engine.transform(self.paxtree(), context)
+            pt = self.paxtree()
+            result = tr_engine.transform(pt, context)
             result, encoding = encoding_neg.encode(result)
             # now this is hairy: how to get the official (IANA) http name
             # of the encoding based on the python name?
Index: opental/OpenPT/Zpax.py
diff -u opental/OpenPT/Zpax.py:1.3 opental/OpenPT/Zpax.py:1.4
--- opental/OpenPT/Zpax.py:1.3  Sun Apr 13 09:03:15 2003
+++ opental/OpenPT/Zpax.py      Fri Apr 25 12:04:04 2003
@@ -15,13 +15,15 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
-__version__='$Revision: 1.3 $'[11:-2]
+__version__='$Revision: 1.4 $'[11:-2]
 
 from pax import core, backwards_compatibility, __path__
 from pax.textpaxparser import Document as textDocument
 from Globals import Persistent
 import sys
 
+# DANGER! do not import this module in a multi-tasking environment!
+# (in Zope it's fine because it's imported *before* threads are started)
 object = Persistent
 sys.path.append(__path__)
 f = core.__file__
@@ -32,6 +34,9 @@
 class Document(Container):
     def __repr__(self):
         return u'<OpenPT Document: %s>' % self.children
+
+    def __xml__(self, ns_map):
+        return XML(self.children)
 
 class Broken_HTML_Element(Element):
     def __children_xml__(self, prefix, ns_map):
Index: opental/pax/core.py
diff -u opental/pax/core.py:1.16 opental/pax/core.py:1.17
--- opental/pax/core.py:1.16    Wed Feb 26 14:59:14 2003
+++ opental/pax/core.py Fri Apr 25 12:04:04 2003
@@ -201,6 +201,8 @@
 
     __str__ = __xml__
 
+    __unicode__ = __xml__
+
     def __repr__(self):
         return '<Literal %s>' % repr(self.text)
 
Index: opental/pax/paxtransform.py
diff -u opental/pax/paxtransform.py:1.33 opental/pax/paxtransform.py:1.34
--- opental/pax/paxtransform.py:1.33    Mon Apr 14 18:13:02 2003
+++ opental/pax/paxtransform.py Fri Apr 25 12:04:04 2003
@@ -41,7 +41,7 @@
             result = element.copy()
         except AttributeError:
             return element
-        __traceback_info__ = getattr(element, 'raw', repr(element))
+        __traceback_info__ = getattr(element, 'raw', repr(element))[:30] + 
'...'
         processed = []
         error_handler = getattr(element, 'transform_error_handler', None)
         if error_handler:
@@ -55,7 +55,6 @@
             result = pack_list(result)
         except:
             # usually we're not interested in errors from pack
-            traceback.print_exc()
             pass
         context.postprocess_remaining = processed
         try:
@@ -118,19 +117,33 @@
 
 class RenderingEngine(Engine):
     "Transforms something, and renders it to XML"
+    def _seq_to_unicode(self, seq, encoding):
+        seq = list(seq)
+        for i, e in enumerate(seq):
+            if type(e) in (types.StringType, types.UnicodeType):
+                continue
+            if e is None:
+                seq[i] = u''
+                continue
+            try:
+                seq[i] = unicode(e)
+            except:
+                seq[i] = unicode(str(e), encoding)
+        return ''.join(seq)
+
     def transform(self, element, context):
         result = Engine.transform(self, element, context)
-        if hasattr(result, 'children'):
+        if hasattr(result, '__xml__'):
             return XML(result, context.root_xmlns_map, context.encoding)
         elif type(result) in (types.ListType, types.TupleType):
-            return ''.join([str(child) for child in result])
+            return self._seq_to_unicode(result, context.encoding)
         return result
 
     def transform_children(self,element,context):
         element = Engine.transform_children(self, element, context)
         # except that the children will be strings
         if hasattr(element, 'children'):
-            element.children = (Literal(''.join([str(child) for child in 
element if child])),)
+            element.children = (Literal(self._seq_to_unicode(element, 
context.encoding)),)
         return element
 
 
Index: opental/pax/textpaxparser.py
diff -u opental/pax/textpaxparser.py:1.5 opental/pax/textpaxparser.py:1.6
--- opental/pax/textpaxparser.py:1.5    Thu Feb 20 05:41:19 2003
+++ opental/pax/textpaxparser.py        Fri Apr 25 12:04:04 2003
@@ -10,12 +10,16 @@
 # <textarea />, <a />, <select /> etc
 
 import core
+from utils import XML
 from HTMLParser import HTMLParser
 from backwards_compatibility import *
 
 class Document(core.Container):
     def __repr__(self):
         return u'<PAX Document: %s>' % self.children
+
+    def __xml__(self, ns_map):
+        return XML(self.children)
 
 # get a namespace, if provided
 def split_ns(spec, default=u''):




reply via email to

[Prev in Thread] Current Thread [Next in Thread]