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, entities={})
| 16 | return s |
| 17 | |
| 18 | def escape(data, entities={}): |
| 19 | """Escape &, <, and > in a string of data. |
| 20 | |
| 21 | You can escape other strings of data by passing a dictionary as |
| 22 | the optional entities parameter. The keys and values must all be |
| 23 | strings; each key will be replaced with its corresponding value. |
| 24 | """ |
| 25 | |
| 26 | # must do ampersand first |
| 27 | data = data.replace("&", "&") |
| 28 | data = data.replace(">", ">") |
| 29 | data = data.replace("<", "<") |
| 30 | if entities: |
| 31 | data = __dict_replace(data, entities) |
| 32 | return data |
| 33 | |
| 34 | def unescape(data, entities={}): |
| 35 | """Unescape &, <, and > in a string of data. |
searching dependent graphs…