File: __init__.py

package info (click to toggle)
python-xml 0.4.19981014-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 2,124 kB
  • ctags: 3,099
  • sloc: ansic: 9,075; python: 8,150; xml: 7,940; makefile: 84; sh: 41
file content (18 lines) | stat: -rw-r--r-- 594 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

__all__ = ['iso8601']

import string
def escape(data, entities = {}):
    """Escape &, <, and > in a string of data.
    You can escape other strings of data by passing a dictionary as 
    the optional entities parameter.  The keys and values must all be
    strings; each key will be replaced with its corresponding value.
    """
    data = string.replace(data, "&", "&amp;")
    data = string.replace(data, "<", "&lt;")
    data = string.replace(data, ">", "&gt;")
    for chars, entity in entities.items():
        data = string.replace(data, chars, entity)        
    return data