Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(159237)

Side by Side Diff: Lib/cgi.py

Issue 2830: Copy cgi.escape() to html
Patch Set: Created 9 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/markup.rst ('k') | Lib/html/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/local/bin/python 1 #! /usr/local/bin/python
2 2
3 # NOTE: the above "/usr/local/bin/python" is NOT a mistake. It is 3 # NOTE: the above "/usr/local/bin/python" is NOT a mistake. It is
4 # intentionally NOT "/usr/bin/env python". On many systems 4 # intentionally NOT "/usr/bin/env python". On many systems
5 # (e.g. Solaris), /usr/local/bin is not in $PATH as passed to CGI 5 # (e.g. Solaris), /usr/local/bin is not in $PATH as passed to CGI
6 # scripts, and /usr/local/bin is the default directory where Python is 6 # scripts, and /usr/local/bin is the default directory where Python is
7 # installed, so /usr/bin/env would be unable to find python. Granted, 7 # installed, so /usr/bin/env would be unable to find python. Granted,
8 # binary installations by Linux vendors often install Python in 8 # binary installations by Linux vendors often install Python in
9 # /usr/bin. So let those vendors patch cgi.py to match their choice 9 # /usr/bin. So let those vendors patch cgi.py to match their choice
10 # of installation. 10 # of installation.
(...skipping 20 matching lines...) Expand all
31 # Imports 31 # Imports
32 # ======= 32 # =======
33 33
34 from operator import attrgetter 34 from operator import attrgetter
35 from io import StringIO 35 from io import StringIO
36 import sys 36 import sys
37 import os 37 import os
38 import urllib.parse 38 import urllib.parse
39 import email.parser 39 import email.parser
40 from warnings import warn 40 from warnings import warn
41 import html
41 42
42 __all__ = ["MiniFieldStorage", "FieldStorage", 43 __all__ = ["MiniFieldStorage", "FieldStorage",
43 "parse", "parse_qs", "parse_qsl", "parse_multipart", 44 "parse", "parse_qs", "parse_qsl", "parse_multipart",
44 "parse_header", "print_exception", "print_environ", 45 "parse_header", "print_exception", "print_environ",
45 "print_form", "print_directory", "print_arguments", 46 "print_form", "print_directory", "print_arguments",
46 "print_environ_usage", "escape"] 47 "print_environ_usage", "escape"]
47 48
48 # Logging support 49 # Logging support
49 # =============== 50 # ===============
50 51
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 <LI>HTTP_REFERER 893 <LI>HTTP_REFERER
893 <LI>HTTP_USER_AGENT 894 <LI>HTTP_USER_AGENT
894 </UL> 895 </UL>
895 """) 896 """)
896 897
897 898
898 # Utilities 899 # Utilities
899 # ========= 900 # =========
900 901
901 def escape(s, quote=None): 902 def escape(s, quote=None):
902 '''Replace special characters "&", "<" and ">" to HTML-safe sequences. 903 """Deprecated API."""
903 If the optional flag quote is true, the quotation mark character (") 904 warn("cgi.escape is deprecated, use html.escape instead",
904 is also translated.''' 905 PendingDeprecationWarning)
905 s = s.replace("&", "&amp;") # Must be done first! 906 return html.escape(s, quote)
906 s = s.replace("<", "&lt;")
907 s = s.replace(">", "&gt;")
908 if quote:
909 s = s.replace('"', "&quot;")
910 return s
911 907
912 def valid_boundary(s, _vb_pattern="^[ -~]{0,200}[!-~]$"): 908 def valid_boundary(s, _vb_pattern="^[ -~]{0,200}[!-~]$"):
913 import re 909 import re
914 return re.match(_vb_pattern, s) 910 return re.match(_vb_pattern, s)
915 911
916 # Invoke mainline 912 # Invoke mainline
917 # =============== 913 # ===============
918 914
919 # Call test() when this file is run as a script (not imported as a module) 915 # Call test() when this file is run as a script (not imported as a module)
920 if __name__ == '__main__': 916 if __name__ == '__main__':
921 test() 917 test()
OLDNEW
« no previous file with comments | « Doc/library/markup.rst ('k') | Lib/html/__init__.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+