OILS / pylib / cgi.py View on Github | oilshell.org

19 lines, 5 significant
1"""
2cgi.py - Copied from Python stdlib.
3
4We don't want the side effects of importing tempfile, which imports random,
5which 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
11def 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("&", "&amp;") # Must be done first!
17 s = s.replace("<", "&lt;")
18 s = s.replace(">", "&gt;")
19 return s