~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Aaron Bentley
  • Date: 2006-07-10 19:23:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1848.
  • Revision ID: abentley@panoramicfeedback.com-20060710192353-469477798c5c4139
Switch to John Meinel's _unescape_xml implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
2152
2152
        versionedfile.clear_cache()
2153
2153
 
2154
2154
 
2155
 
_unsafe_entities = None
2156
 
 
2157
 
 
2158
 
# Copied from xml.sax.saxutils
2159
 
# ADHB xml.sax.saxutils is horrendously broken!  apos and quot are predefined
2160
 
# according to XML 1.0 section 4.6
 
2155
_unescape_map = {
 
2156
    'apos':"'",
 
2157
    'quot':'"',
 
2158
    'amp':'&',
 
2159
    'lt':'<',
 
2160
    'gt':'>'
 
2161
}
 
2162
 
 
2163
 
 
2164
def _unescaper(match, _map=_unescape_map):
 
2165
    return _map[match.group(1)]
 
2166
 
 
2167
 
 
2168
_unescape_re = None
 
2169
 
 
2170
 
2161
2171
def _unescape_xml(data):
2162
 
    """Unescape predefined entities in a string of data.
2163
 
    """
2164
 
    global _unsafe_entities
2165
 
    if _unsafe_entities is None:
2166
 
        _unsafe_entities = re.compile('\&(?!amp;|lt;|gt;|apos;|quot;)[^;]*')
2167
 
    unsafe = _unsafe_entities.search(data)
2168
 
    assert unsafe is None, 'Unhandled entity: %s' % unsafe.group(0)
2169
 
    data = data.replace("&lt;", "<")
2170
 
    data = data.replace("&gt;", ">")
2171
 
    data = data.replace("&quot;", '"')
2172
 
    data = data.replace("&apos;", "'")
2173
 
    # must do ampersand last
2174
 
    return data.replace("&amp;", "&")
 
2172
    """Unescape predefined XML entities in a string of data."""
 
2173
    global _unescape_re
 
2174
    if _unescape_re is None:
 
2175
        _unescape_re = re.compile('\&([^;]*);')
 
2176
    return _unescape_re.sub(_unescaper, data)