| 1 | """
 | 
| 2 | cgi.py - Copied from Python stdlib.
 | 
| 3 | 
 | 
| 4 | We don't want the side effects of importing tempfile, which imports random,
 | 
| 5 | which opens /dev/urandom!
 | 
| 6 | """
 | 
| 7 | 
 | 
| 8 | # Removed quote arg since C++ doesn't support keyword args, and we don't use it
 | 
| 9 | # in Oil proper.
 | 
| 10 | 
 | 
| 11 | def escape(s):
 | 
| 12 |     # type: (str) -> str
 | 
| 13 |     '''Replace special characters "&", "<" and ">" to HTML-safe sequences.
 | 
| 14 |     If the optional flag quote is true, the quotation mark character (")
 | 
| 15 |     is also translated.'''
 | 
| 16 |     s = s.replace("&", "&") # Must be done first!
 | 
| 17 |     s = s.replace("<", "<")
 | 
| 18 |     s = s.replace(">", ">")
 | 
| 19 |     return s
 |