Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0e94e51efb
Fetching contributors…

Cannot retrieve contributors at this time

file 32 lines (24 sloc) 0.612 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Filter for escaping unsafe XML characters: <, >, &
@author Sergey Chikuyonok (serge.che@gmail.com)
@link http://chikuyonok.ru
'''
import re

alias = 'e'
"Filter name alias (if not defined, ZC will use module name)"

char_map = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;'
}

re_chars = re.compile(r'[<>&]')

def escape_chars(text):
return re_chars.sub(lambda m: char_map[m.group(0)], text)

def process(tree, profile=None):
for item in tree.children:
item.start = escape_chars(item.start)
item.end = escape_chars(item.end)

process(item)

return tree
Something went wrong with that request. Please try again.