opental-checkins
[Top][All Lists]
Advanced

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

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


From: Fernando Lalo Martins
Subject: [OpenTAL-checkins] opental OpenPT/Zpax.py pax/core.py pax/htmlpaxp...
Date: Fri, 21 Feb 2003 13:37:05 -0500

CVSROOT:        /cvsroot/opental
Module name:    opental
Changes by:     Fernando Lalo Martins <address@hidden>  03/02/21 13:37:05

Modified files:
        OpenPT         : Zpax.py 
        pax            : core.py htmlpaxparser.py 

Log message:
        the new feature of overridable classes in parsers broke htmlpaxparser; 
this was perhaps a good thing as now the implementation is much cleaner ;-)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/OpenPT/Zpax.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/pax/core.py.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/opental/opental/pax/htmlpaxparser.py.diff?tr1=1.19&tr2=1.20&r1=text&r2=text

Patches:
Index: opental/OpenPT/Zpax.py
diff -u opental/OpenPT/Zpax.py:1.1 opental/OpenPT/Zpax.py:1.2
--- opental/OpenPT/Zpax.py:1.1  Thu Feb 20 05:37:40 2003
+++ opental/OpenPT/Zpax.py      Fri Feb 21 13:37:05 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.1 $'[11:-2]
+__version__='$Revision: 1.2 $'[11:-2]
 
 from pax import core, backwards_compatibility, __path__
 from pax.textpaxparser import Document as textDocument
@@ -32,3 +32,12 @@
 class Document(Container):
     def __repr__(self):
         return u'<OpenPT Document: %s>' % self.children
+
+class Broken_HTML_Element(Element):
+    def __children_xml__(self, prefix, ns_map):
+        return u'>' + XML(self.children, ns_map) + u'</' + prefix + self.name 
+ u'>'
+
+class Raw_HTML_Element(Element):
+    def __children_xml__(self, prefix, ns_map):
+        return u'>' + u''.join(self) + u'</' + prefix + self.name + u'>'
+
Index: opental/pax/core.py
diff -u opental/pax/core.py:1.14 opental/pax/core.py:1.15
--- opental/pax/core.py:1.14    Mon Jan 27 02:05:12 2003
+++ opental/pax/core.py Fri Feb 21 13:37:05 2003
@@ -63,8 +63,10 @@
                 attributes[duri] = {}
         self.raw = raw
 
-    def copy(self):
-        copy = self.__class__(self.ns, self.name, {}, self.nsdecls.copy(), 
self.raw)
+    def copy(self, newclass=None):
+        if newclass is None:
+            newclass = self.__class__
+        copy = newclass(self.ns, self.name, {}, self.nsdecls.copy(), self.raw)
         # attributes is copied with one level of depth
         for ns, attrs in self.attributes.items():
             copy.attributes[ns] = attrs.copy()
Index: opental/pax/htmlpaxparser.py
diff -u opental/pax/htmlpaxparser.py:1.19 opental/pax/htmlpaxparser.py:1.20
--- opental/pax/htmlpaxparser.py:1.19   Thu Feb 20 05:41:18 2003
+++ opental/pax/htmlpaxparser.py        Fri Feb 21 13:37:05 2003
@@ -30,13 +30,27 @@
         return u'>' + u''.join(self) + u'</' + prefix + self.name + u'>'
 
 class _parse_in_progress(_text_parse):
+    def __init__(self, *a, **kw):
+        _text_parse.__init__(self, *a, **kw)
+        if hasattr(self._module, 'Broken_HTML_Element'):
+            self._broken = self._module.Broken_HTML_Element
+        else:
+            self._broken = Broken_HTML_Element
+        if hasattr(self._module, 'Raw_HTML_Element'):
+            self._raw = self._module.Raw_HTML_Element
+        else:
+            self._raw = Raw_HTML_Element
+
     def handle_starttag(self, rawname, raw_attributes):
         _text_parse.handle_starttag(self, rawname, raw_attributes)
         element = self.stack[-1]
         if element.name in broken:
-            element.__class__ = Broken_HTML_Element
-        if element.name in raw:
-            element.__class__ = Raw_HTML_Element
+            element = element.copy(self._broken)
+        elif element.name in raw:
+            element = element.copy(self._raw)
+        else:
+            return
+        self.stack[-1] = element
 
 def parse(data, builtin_namespaces=None, encoding=None, module=core):
     if encoding is None:




reply via email to

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