Skip to content

Instantly share code, notes, and snippets.

@niallo
Created August 5, 2010 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niallo/509164 to your computer and use it in GitHub Desktop.
Save niallo/509164 to your computer and use it in GitHub Desktop.
_xml_escapes = (tuple([('%c' % z, '\\u%04X' % z)
for z in range(20) if z not in (0x9, 0xA, 0xD)]))
def escape_low_xml(value):
''' Escape every ASCII character with a value less than 20 except for
certain codes allowed by XML v1.0 spec '''
for bad, good in _xml_escapes:
value = value.replace(bad, good)
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment