Escape and quote an attribute value. Escape &, <, and > in a string of data, then quote it for use as an attribute value. The \" character will be escaped as well, if necessary. You can escape other strings of data by passing a dictionary as the optional entities parameter. T
(data, entities={})
| 46 | return data.replace("&", "&") |
| 47 | |
| 48 | def quoteattr(data, entities={}): |
| 49 | """Escape and quote an attribute value. |
| 50 | |
| 51 | Escape &, <, and > in a string of data, then quote it for use as |
| 52 | an attribute value. The \" character will be escaped as well, if |
| 53 | necessary. |
| 54 | |
| 55 | You can escape other strings of data by passing a dictionary as |
| 56 | the optional entities parameter. The keys and values must all be |
| 57 | strings; each key will be replaced with its corresponding value. |
| 58 | """ |
| 59 | entities = {**entities, '\n': ' ', '\r': ' ', '\t':'	'} |
| 60 | data = escape(data, entities) |
| 61 | if '"' in data: |
| 62 | if "'" in data: |
| 63 | data = '"%s"' % data.replace('"', """) |
| 64 | else: |
| 65 | data = "'%s'" % data |
| 66 | else: |
| 67 | data = '"%s"' % data |
| 68 | return data |
| 69 | |
| 70 | |
| 71 | def _gettextwriter(out, encoding): |
searching dependent graphs…