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

Side by Side Diff: third_party/markupsafe/_native.py

Issue 23445019: Add MarkupSafe library to third_party (dependency for Jinja2 2.7) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « third_party/markupsafe/_constants.py ('k') | third_party/markupsafe/_speedups.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """ 2 """
3 markupsafe._native 3 markupsafe._native
4 ~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~
5 5
6 Native Python implementation the C module is not compiled. 6 Native Python implementation the C module is not compiled.
7 7
8 :copyright: (c) 2010 by Armin Ronacher. 8 :copyright: (c) 2010 by Armin Ronacher.
9 :license: BSD, see LICENSE for more details. 9 :license: BSD, see LICENSE for more details.
10 """ 10 """
11 from jinja2._markupsafe import Markup 11 from markupsafe import Markup
12 from markupsafe._compat import text_type
12 13
13 14
14 def escape(s): 15 def escape(s):
15 """Convert the characters &, <, >, ' and " in string s to HTML-safe 16 """Convert the characters &, <, >, ' and " in string s to HTML-safe
16 sequences. Use this if you need to display text that might contain 17 sequences. Use this if you need to display text that might contain
17 such characters in HTML. Marks return value as markup string. 18 such characters in HTML. Marks return value as markup string.
18 """ 19 """
19 if hasattr(s, '__html__'): 20 if hasattr(s, '__html__'):
20 return s.__html__() 21 return s.__html__()
21 return Markup(unicode(s) 22 return Markup(text_type(s)
22 .replace('&', '&amp;') 23 .replace('&', '&amp;')
23 .replace('>', '&gt;') 24 .replace('>', '&gt;')
24 .replace('<', '&lt;') 25 .replace('<', '&lt;')
25 .replace("'", '&#39;') 26 .replace("'", '&#39;')
26 .replace('"', '&#34;') 27 .replace('"', '&#34;')
27 ) 28 )
28 29
29 30
30 def escape_silent(s): 31 def escape_silent(s):
31 """Like :func:`escape` but converts `None` into an empty 32 """Like :func:`escape` but converts `None` into an empty
32 markup string. 33 markup string.
33 """ 34 """
34 if s is None: 35 if s is None:
35 return Markup() 36 return Markup()
36 return escape(s) 37 return escape(s)
37 38
38 39
39 def soft_unicode(s): 40 def soft_unicode(s):
40 """Make a string unicode if it isn't already. That way a markup 41 """Make a string unicode if it isn't already. That way a markup
41 string is not converted back to unicode. 42 string is not converted back to unicode.
42 """ 43 """
43 if not isinstance(s, unicode): 44 if not isinstance(s, text_type):
44 s = unicode(s) 45 s = text_type(s)
45 return s 46 return s
OLDNEW
« no previous file with comments | « third_party/markupsafe/_constants.py ('k') | third_party/markupsafe/_speedups.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698