~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml_serializer.py

  • Committer: Jelmer Vernooij
  • Date: 2009-04-03 23:18:11 UTC
  • mfrom: (4252 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4253.
  • Revision ID: jelmer@samba.org-20090403231811-8yh9yi6xl2lfce1v
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
        elementtree.ElementTree._raise_serialization_error(text)
167
167
 
168
168
elementtree.ElementTree._escape_cdata = _escape_cdata
 
169
 
 
170
 
 
171
def escape_invalid_chars(message):
 
172
    """Escape the XML-invalid characters in a commit message.
 
173
 
 
174
    :param message: Commit message to escape
 
175
    :param count: Number of characters that were escaped
 
176
    """
 
177
    # Python strings can include characters that can't be
 
178
    # represented in well-formed XML; escape characters that
 
179
    # aren't listed in the XML specification
 
180
    # (http://www.w3.org/TR/REC-xml/#NT-Char).
 
181
    return re.subn(u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
 
182
            lambda match: match.group(0).encode('unicode_escape'),
 
183
            message)