Rev 5407: (jameinel) Remove monkey patching for elementtree, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Sep 3 01:13:59 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5407 [merge]
revision-id: pqm at pqm.ubuntu.com-20100903001355-l29hnxtjgnlhpq2f
parent: pqm at pqm.ubuntu.com-20100902225129-83167cameln73xz2
parent: gzlist at googlemail.com-20100829183846-7yie51e2tqn2xl6w
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-09-03 01:13:55 +0100
message:
  (jameinel) Remove monkey patching for elementtree,
   we do it differently anyway (Martin [gz])
modified:
  bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
=== modified file 'bzrlib/xml_serializer.py'
--- a/bzrlib/xml_serializer.py	2010-05-25 17:27:52 +0000
+++ b/bzrlib/xml_serializer.py	2010-08-29 18:38:46 +0000
@@ -22,6 +22,8 @@
 # importing this module is fairly slow because it has to load several
 # ElementTree bits
 
+import re
+
 from bzrlib.serializer import Serializer
 from bzrlib.trace import mutter
 
@@ -111,73 +113,6 @@
         return ElementTree().parse(f)
 
 
-# performance tuning for elementree's serialiser. This should be
-# sent upstream - RBC 20060523.
-# the functions here are patched into elementtree at runtime.
-import re
-escape_re = re.compile("[&'\"<>]")
-escape_map = {
-    "&":'&amp;',
-    "'":"&apos;", # FIXME: overkill
-    "\"":"&quot;",
-    "<":"&lt;",
-    ">":"&gt;",
-    }
-def _escape_replace(match, map=escape_map):
-    return map[match.group()]
-
-def _escape_attrib(text, encoding=None, replace=None):
-    # escape attribute value
-    try:
-        if encoding:
-            try:
-                text = elementtree.ElementTree._encode(text, encoding)
-            except UnicodeError:
-                return elementtree.ElementTree._encode_entity(text)
-        if replace is None:
-            return escape_re.sub(_escape_replace, text)
-        else:
-            text = replace(text, "&", "&amp;")
-            text = replace(text, "'", "&apos;") # FIXME: overkill
-            text = replace(text, "\"", "&quot;")
-            text = replace(text, "<", "&lt;")
-            text = replace(text, ">", "&gt;")
-            return text
-    except (TypeError, AttributeError):
-        elementtree.ElementTree._raise_serialization_error(text)
-
-elementtree.ElementTree._escape_attrib = _escape_attrib
-
-escape_cdata_re = re.compile("[&<>]")
-escape_cdata_map = {
-    "&":'&amp;',
-    "<":"&lt;",
-    ">":"&gt;",
-    }
-def _escape_cdata_replace(match, map=escape_cdata_map):
-    return map[match.group()]
-
-def _escape_cdata(text, encoding=None, replace=None):
-    # escape character data
-    try:
-        if encoding:
-            try:
-                text = elementtree.ElementTree._encode(text, encoding)
-            except UnicodeError:
-                return elementtree.ElementTree._encode_entity(text)
-        if replace is None:
-            return escape_cdata_re.sub(_escape_cdata_replace, text)
-        else:
-            text = replace(text, "&", "&amp;")
-            text = replace(text, "<", "&lt;")
-            text = replace(text, ">", "&gt;")
-            return text
-    except (TypeError, AttributeError):
-        elementtree.ElementTree._raise_serialization_error(text)
-
-elementtree.ElementTree._escape_cdata = _escape_cdata
-
-
 def escape_invalid_chars(message):
     """Escape the XML-invalid characters in a commit message.
 




More information about the bazaar-commits mailing list