OLD | NEW |
(Empty) | |
| 1 from __future__ import absolute_import |
| 2 from future.utils import PY3 |
| 3 __future_module__ = True |
| 4 |
| 5 if PY3: |
| 6 from html import * |
| 7 else: |
| 8 # cgi.escape isn't good enough for the single Py3.3 html test to pass. |
| 9 # Define it inline here instead. From the Py3.4 stdlib. Note that the |
| 10 # html.escape() function from the Py3.3 stdlib is not suitable for use on |
| 11 # Py2.x. |
| 12 """ |
| 13 General functions for HTML manipulation. |
| 14 """ |
| 15 |
| 16 def escape(s, quote=True): |
| 17 """ |
| 18 Replace special characters "&", "<" and ">" to HTML-safe sequences. |
| 19 If the optional flag quote is true (the default), the quotation mark |
| 20 characters, both double quote (") and single quote (') characters are al
so |
| 21 translated. |
| 22 """ |
| 23 s = s.replace("&", "&") # Must be done first! |
| 24 s = s.replace("<", "<") |
| 25 s = s.replace(">", ">") |
| 26 if quote: |
| 27 s = s.replace('"', """) |
| 28 s = s.replace('\'', "'") |
| 29 return s |
| 30 |
| 31 __all__ = ['escape'] |
OLD | NEW |