Rev 4238: (Jelmer) Make function for escaping invalid XML characters public. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Apr 2 14:58:09 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4238
revision-id: pqm at pqm.ubuntu.com-20090402135806-w2vi86mmi1s39b4h
parent: pqm at pqm.ubuntu.com-20090402093220-mqwls6dsncdfegbq
parent: jelmer at samba.org-20090331203433-ncsd0sar9rc7wkqd
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-04-02 14:58:06 +0100
message:
(Jelmer) Make function for escaping invalid XML characters public.
modified:
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/xml_serializer.py xml.py-20050309040759-57d51586fdec365d
------------------------------------------------------------
revno: 4222.1.1
revision-id: jelmer at samba.org-20090331203433-ncsd0sar9rc7wkqd
parent: pqm at pqm.ubuntu.com-20090331122525-77wqe7gqpr2gcl7u
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: escape-commit-message
timestamp: Tue 2009-03-31 22:34:33 +0200
message:
Make function for escaping invalid XML characters public.
modified:
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/xml_serializer.py xml.py-20050309040759-57d51586fdec365d
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2009-03-27 04:36:58 +0000
+++ b/bzrlib/commit.py 2009-03-31 20:34:33 +0000
@@ -62,6 +62,7 @@
revision,
trace,
tree,
+ xml_serializer,
)
from bzrlib.branch import Branch
import bzrlib.config
@@ -607,14 +608,7 @@
# serialiser not by commit. Then we can also add an unescaper
# in the deserializer and start roundtripping revision messages
# precisely. See repository_implementations/test_repository.py
-
- # Python strings can include characters that can't be
- # represented in well-formed XML; escape characters that
- # aren't listed in the XML specification
- # (http://www.w3.org/TR/REC-xml/#NT-Char).
- self.message, escape_count = re.subn(
- u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
- lambda match: match.group(0).encode('unicode_escape'),
+ self.message, escape_count = xml_serializer.escape_invalid_chars(
self.message)
if escape_count:
self.reporter.escaped(escape_count, self.message)
=== modified file 'bzrlib/xml_serializer.py'
--- a/bzrlib/xml_serializer.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/xml_serializer.py 2009-03-31 20:34:33 +0000
@@ -185,3 +185,19 @@
format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6')
format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7')
format_registry.register_lazy('8', 'bzrlib.xml8', 'serializer_v8')
+
+
+def escape_invalid_chars(message):
+ """Escape the XML-invalid characters in a commit message.
+
+ :param message: Commit message to escape
+ :param count: Number of characters that were escaped
+ """
+ # Python strings can include characters that can't be
+ # represented in well-formed XML; escape characters that
+ # aren't listed in the XML specification
+ # (http://www.w3.org/TR/REC-xml/#NT-Char).
+ return re.subn(u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
+ lambda match: match.group(0).encode('unicode_escape'),
+ message)
+
More information about the bazaar-commits
mailing list