mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
[py3] Replaced unicode/str by six.text_type/bytes.
This commit is contained in:
@@ -10,6 +10,7 @@ import urlparse
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from django.utils.encoding import smart_str, force_unicode
|
||||
from django.utils.functional import allow_lazy
|
||||
from django.utils import six
|
||||
from django.utils.text import normalize_newlines
|
||||
|
||||
# Configuration for urlize() function.
|
||||
@@ -36,7 +37,7 @@ def escape(text):
|
||||
Returns the given text with ampersands, quotes and angle brackets encoded for use in HTML.
|
||||
"""
|
||||
return mark_safe(force_unicode(text).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", '''))
|
||||
escape = allow_lazy(escape, unicode)
|
||||
escape = allow_lazy(escape, six.text_type)
|
||||
|
||||
_base_js_escapes = (
|
||||
('\\', '\\u005C'),
|
||||
@@ -61,7 +62,7 @@ def escapejs(value):
|
||||
for bad, good in _js_escapes:
|
||||
value = mark_safe(force_unicode(value).replace(bad, good))
|
||||
return value
|
||||
escapejs = allow_lazy(escapejs, unicode)
|
||||
escapejs = allow_lazy(escapejs, six.text_type)
|
||||
|
||||
def conditional_escape(text):
|
||||
"""
|
||||
@@ -112,7 +113,7 @@ def linebreaks(value, autoescape=False):
|
||||
else:
|
||||
paras = ['<p>%s</p>' % p.replace('\n', '<br />') for p in paras]
|
||||
return '\n\n'.join(paras)
|
||||
linebreaks = allow_lazy(linebreaks, unicode)
|
||||
linebreaks = allow_lazy(linebreaks, six.text_type)
|
||||
|
||||
def strip_tags(value):
|
||||
"""Returns the given HTML with all tags stripped."""
|
||||
@@ -122,17 +123,17 @@ strip_tags = allow_lazy(strip_tags)
|
||||
def strip_spaces_between_tags(value):
|
||||
"""Returns the given HTML with spaces between tags removed."""
|
||||
return re.sub(r'>\s+<', '><', force_unicode(value))
|
||||
strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode)
|
||||
strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, six.text_type)
|
||||
|
||||
def strip_entities(value):
|
||||
"""Returns the given HTML with all entities (&something;) stripped."""
|
||||
return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value))
|
||||
strip_entities = allow_lazy(strip_entities, unicode)
|
||||
strip_entities = allow_lazy(strip_entities, six.text_type)
|
||||
|
||||
def fix_ampersands(value):
|
||||
"""Returns the given HTML with all unencoded ampersands encoded correctly."""
|
||||
return unencoded_ampersands_re.sub('&', force_unicode(value))
|
||||
fix_ampersands = allow_lazy(fix_ampersands, unicode)
|
||||
fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
|
||||
|
||||
def smart_urlquote(url):
|
||||
"Quotes a URL if it isn't already quoted."
|
||||
@@ -226,7 +227,7 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
|
||||
elif autoescape:
|
||||
words[i] = escape(word)
|
||||
return ''.join(words)
|
||||
urlize = allow_lazy(urlize, unicode)
|
||||
urlize = allow_lazy(urlize, six.text_type)
|
||||
|
||||
def clean_html(text):
|
||||
"""
|
||||
@@ -260,4 +261,4 @@ def clean_html(text):
|
||||
# of the text.
|
||||
text = trailing_empty_content_re.sub('', text)
|
||||
return text
|
||||
clean_html = allow_lazy(clean_html, unicode)
|
||||
clean_html = allow_lazy(clean_html, six.text_type)
|
||||
|
||||
Reference in New Issue
Block a user