Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: third_party/google-endpoints/future/backports/html/__init__.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 """
2 General functions for HTML manipulation, backported from Py3.
3
4 Note that this uses Python 2.7 code with the corresponding Python 3
5 module names and locations.
6 """
7
8 from __future__ import unicode_literals
9
10
11 _escape_map = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;'}
12 _escape_map_full = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;',
13 ord('"'): '&quot;', ord('\''): '&#x27;'}
14
15 # NB: this is a candidate for a bytes/string polymorphic interface
16
17 def escape(s, quote=True):
18 """
19 Replace special characters "&", "<" and ">" to HTML-safe sequences.
20 If the optional flag quote is true (the default), the quotation mark
21 characters, both double quote (") and single quote (') characters are also
22 translated.
23 """
24 assert not isinstance(s, bytes), 'Pass a unicode string'
25 if quote:
26 return s.translate(_escape_map_full)
27 return s.translate(_escape_map)
28
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698