Loading django/template/defaultfilters.py +1 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ from django.conf import settings from django.utils import formats from django.utils.dateformat import format, time_format from django.utils.encoding import force_text, iri_to_uri from django.utils.html import (conditional_escape, escapejs, fix_ampersands, from django.utils.html import (conditional_escape, escapejs, escape, urlize as _urlize, linebreaks, strip_tags, avoid_wrapping, remove_tags) from django.utils.http import urlquote Loading Loading @@ -82,12 +82,6 @@ def escapejs_filter(value): return escapejs(value) @register.filter("fix_ampersands", is_safe=True) @stringfilter def fix_ampersands_filter(value): """Replaces ampersands with ``&`` entities.""" return fix_ampersands(value) # Values for testing floatformat input against infinity and NaN representations, # which differ across platforms and Python versions. Some (i.e. old Windows # ones) are not recognized by Decimal but we want to return them unchanged vs. Loading django/utils/html.py +0 −49 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ from __future__ import unicode_literals import re import warnings from django.utils.deprecation import RemovedInDjango18Warning from django.utils.encoding import force_text, force_str from django.utils.functional import allow_lazy from django.utils.safestring import SafeData, mark_safe Loading Loading @@ -174,15 +172,6 @@ def strip_entities(value): strip_entities = allow_lazy(strip_entities, six.text_type) def fix_ampersands(value): """Returns the given HTML with all unencoded ampersands encoded correctly.""" # As fix_ampersands is wrapped in allow_lazy, stacklevel 3 is more useful than 2. warnings.warn("The fix_ampersands function is deprecated and will be removed in Django 1.8.", RemovedInDjango18Warning, stacklevel=3) return unencoded_ampersands_re.sub('&', force_text(value)) fix_ampersands = allow_lazy(fix_ampersands, six.text_type) def smart_urlquote(url): "Quotes a URL if it isn't already quoted." # Handle IDN before quoting. Loading Loading @@ -283,44 +272,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): urlize = allow_lazy(urlize, six.text_type) def clean_html(text): """ Clean the given HTML. Specifically, do the following: * Convert <b> and <i> to <strong> and <em>. * Encode all ampersands correctly. * Remove all "target" attributes from <a> tags. * Remove extraneous HTML, such as presentational tags that open and immediately close and <br clear="all">. * Convert hard-coded bullets into HTML unordered lists. * Remove stuff like "<p> </p>", but only if it's at the bottom of the text. """ # As clean_html is wrapped in allow_lazy, stacklevel 3 is more useful than 2. warnings.warn("The clean_html function is deprecated and will be removed in Django 1.8.", RemovedInDjango18Warning, stacklevel=3) text = normalize_newlines(text) text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text) text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text) text = fix_ampersands(text) # Remove all target="" attributes from <a> tags. text = link_target_attribute_re.sub('\\1', text) # Trim stupid HTML such as <br clear="all">. text = html_gunk_re.sub('', text) # Convert hard-coded bullets into HTML unordered lists. def replace_p_tags(match): s = match.group().replace('</p>', '</li>') for d in DOTS: s = s.replace('<p>%s' % d, '<li>') return '<ul>\n%s\n</ul>' % s text = hard_coded_bullets_re.sub(replace_p_tags, text) # Remove stuff like "<p> </p>", but only if it's at the bottom # of the text. text = trailing_empty_content_re.sub('', text) return text clean_html = allow_lazy(clean_html, six.text_type) def avoid_wrapping(value): """ Avoid text wrapping in the middle of a phrase by adding non-breaking Loading docs/ref/templates/builtins.txt +0 −29 Original line number Diff line number Diff line Loading @@ -1572,35 +1572,6 @@ For example:: If ``value`` is the list ``['a', 'b', 'c']``, the output will be ``'a'``. .. templatefilter:: fix_ampersands fix_ampersands ^^^^^^^^^^^^^^ .. note:: This is rarely useful as ampersands are automatically escaped. See :tfilter:`escape` for more information. .. deprecated:: 1.7 This filter has been deprecated and will be removed in Django 1.8. Replaces ampersands with ``&`` entities. For example:: {{ value|fix_ampersands }} If ``value`` is ``Tom & Jerry``, the output will be ``Tom & Jerry``. However, ampersands used in named entities and numeric character references will not be replaced. For example, if ``value`` is ``Café``, the output will *not* be ``Caf&eacute;`` but remain ``Café``. This means that in some edge cases, such as acronyms followed by semicolons, this filter will not replace ampersands that need replacing. For example, if ``value`` is ``Contact the R&D;``, the output will remain unchanged because ``&D;`` resembles a named entity. .. templatefilter:: floatformat floatformat Loading tests/defaultfilters/tests.py +1 −9 Original line number Diff line number Diff line Loading @@ -4,12 +4,11 @@ from __future__ import unicode_literals import datetime import decimal import unittest import warnings from django.template.defaultfilters import ( add, addslashes, capfirst, center, cut, date, default, default_if_none, dictsort, dictsortreversed, divisibleby, escape, escapejs_filter, filesizeformat, first, fix_ampersands_filter, floatformat, force_escape, filesizeformat, first, floatformat, force_escape, get_digit, iriencode, join, length, length_is, linebreaksbr, linebreaks_filter, linenumbers, ljust, lower, make_list, phone2numeric_filter, pluralize, removetags, rjust, slice_filter, slugify, Loading @@ -20,7 +19,6 @@ from django.template.defaultfilters import ( from django.test import TestCase from django.utils import six from django.utils import translation from django.utils.deprecation import RemovedInDjango18Warning from django.utils.encoding import python_2_unicode_compatible from django.utils.safestring import SafeData Loading Loading @@ -125,12 +123,6 @@ class DefaultFiltersTests(TestCase): escapejs_filter('paragraph separator:\u2029and line separator:\u2028'), 'paragraph separator:\\u2029and line separator:\\u2028') def test_fix_ampersands(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango18Warning) self.assertEqual(fix_ampersands_filter('Jack & Jill & Jeroboam'), 'Jack & Jill & Jeroboam') def test_linenumbers(self): self.assertEqual(linenumbers('line 1\nline 2'), '1. line 1\n2. line 2') Loading tests/template_tests/filters.py +0 −5 Original line number Diff line number Diff line Loading @@ -104,11 +104,6 @@ def get_filter_tests(): 'filter-capfirst01': ("{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"), 'filter-capfirst02': ("{{ a|capfirst }} {{ b|capfirst }}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"), # Note that applying fix_ampsersands in autoescape mode leads to # double escaping. 'filter-fix_ampersands01': ("{% autoescape off %}{{ a|fix_ampersands }} {{ b|fix_ampersands }}{% endautoescape %}", {"a": "a&b", "b": mark_safe("a&b")}, "a&b a&b"), 'filter-fix_ampersands02': ("{{ a|fix_ampersands }} {{ b|fix_ampersands }}", {"a": "a&b", "b": mark_safe("a&b")}, "a&amp;b a&b"), 'filter-floatformat01': ("{% autoescape off %}{{ a|floatformat }} {{ b|floatformat }}{% endautoescape %}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"), 'filter-floatformat02': ("{{ a|floatformat }} {{ b|floatformat }}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"), Loading Loading
django/template/defaultfilters.py +1 −7 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ from django.conf import settings from django.utils import formats from django.utils.dateformat import format, time_format from django.utils.encoding import force_text, iri_to_uri from django.utils.html import (conditional_escape, escapejs, fix_ampersands, from django.utils.html import (conditional_escape, escapejs, escape, urlize as _urlize, linebreaks, strip_tags, avoid_wrapping, remove_tags) from django.utils.http import urlquote Loading Loading @@ -82,12 +82,6 @@ def escapejs_filter(value): return escapejs(value) @register.filter("fix_ampersands", is_safe=True) @stringfilter def fix_ampersands_filter(value): """Replaces ampersands with ``&`` entities.""" return fix_ampersands(value) # Values for testing floatformat input against infinity and NaN representations, # which differ across platforms and Python versions. Some (i.e. old Windows # ones) are not recognized by Decimal but we want to return them unchanged vs. Loading
django/utils/html.py +0 −49 Original line number Diff line number Diff line Loading @@ -3,9 +3,7 @@ from __future__ import unicode_literals import re import warnings from django.utils.deprecation import RemovedInDjango18Warning from django.utils.encoding import force_text, force_str from django.utils.functional import allow_lazy from django.utils.safestring import SafeData, mark_safe Loading Loading @@ -174,15 +172,6 @@ def strip_entities(value): strip_entities = allow_lazy(strip_entities, six.text_type) def fix_ampersands(value): """Returns the given HTML with all unencoded ampersands encoded correctly.""" # As fix_ampersands is wrapped in allow_lazy, stacklevel 3 is more useful than 2. warnings.warn("The fix_ampersands function is deprecated and will be removed in Django 1.8.", RemovedInDjango18Warning, stacklevel=3) return unencoded_ampersands_re.sub('&', force_text(value)) fix_ampersands = allow_lazy(fix_ampersands, six.text_type) def smart_urlquote(url): "Quotes a URL if it isn't already quoted." # Handle IDN before quoting. Loading Loading @@ -283,44 +272,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): urlize = allow_lazy(urlize, six.text_type) def clean_html(text): """ Clean the given HTML. Specifically, do the following: * Convert <b> and <i> to <strong> and <em>. * Encode all ampersands correctly. * Remove all "target" attributes from <a> tags. * Remove extraneous HTML, such as presentational tags that open and immediately close and <br clear="all">. * Convert hard-coded bullets into HTML unordered lists. * Remove stuff like "<p> </p>", but only if it's at the bottom of the text. """ # As clean_html is wrapped in allow_lazy, stacklevel 3 is more useful than 2. warnings.warn("The clean_html function is deprecated and will be removed in Django 1.8.", RemovedInDjango18Warning, stacklevel=3) text = normalize_newlines(text) text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text) text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text) text = fix_ampersands(text) # Remove all target="" attributes from <a> tags. text = link_target_attribute_re.sub('\\1', text) # Trim stupid HTML such as <br clear="all">. text = html_gunk_re.sub('', text) # Convert hard-coded bullets into HTML unordered lists. def replace_p_tags(match): s = match.group().replace('</p>', '</li>') for d in DOTS: s = s.replace('<p>%s' % d, '<li>') return '<ul>\n%s\n</ul>' % s text = hard_coded_bullets_re.sub(replace_p_tags, text) # Remove stuff like "<p> </p>", but only if it's at the bottom # of the text. text = trailing_empty_content_re.sub('', text) return text clean_html = allow_lazy(clean_html, six.text_type) def avoid_wrapping(value): """ Avoid text wrapping in the middle of a phrase by adding non-breaking Loading
docs/ref/templates/builtins.txt +0 −29 Original line number Diff line number Diff line Loading @@ -1572,35 +1572,6 @@ For example:: If ``value`` is the list ``['a', 'b', 'c']``, the output will be ``'a'``. .. templatefilter:: fix_ampersands fix_ampersands ^^^^^^^^^^^^^^ .. note:: This is rarely useful as ampersands are automatically escaped. See :tfilter:`escape` for more information. .. deprecated:: 1.7 This filter has been deprecated and will be removed in Django 1.8. Replaces ampersands with ``&`` entities. For example:: {{ value|fix_ampersands }} If ``value`` is ``Tom & Jerry``, the output will be ``Tom & Jerry``. However, ampersands used in named entities and numeric character references will not be replaced. For example, if ``value`` is ``Café``, the output will *not* be ``Caf&eacute;`` but remain ``Café``. This means that in some edge cases, such as acronyms followed by semicolons, this filter will not replace ampersands that need replacing. For example, if ``value`` is ``Contact the R&D;``, the output will remain unchanged because ``&D;`` resembles a named entity. .. templatefilter:: floatformat floatformat Loading
tests/defaultfilters/tests.py +1 −9 Original line number Diff line number Diff line Loading @@ -4,12 +4,11 @@ from __future__ import unicode_literals import datetime import decimal import unittest import warnings from django.template.defaultfilters import ( add, addslashes, capfirst, center, cut, date, default, default_if_none, dictsort, dictsortreversed, divisibleby, escape, escapejs_filter, filesizeformat, first, fix_ampersands_filter, floatformat, force_escape, filesizeformat, first, floatformat, force_escape, get_digit, iriencode, join, length, length_is, linebreaksbr, linebreaks_filter, linenumbers, ljust, lower, make_list, phone2numeric_filter, pluralize, removetags, rjust, slice_filter, slugify, Loading @@ -20,7 +19,6 @@ from django.template.defaultfilters import ( from django.test import TestCase from django.utils import six from django.utils import translation from django.utils.deprecation import RemovedInDjango18Warning from django.utils.encoding import python_2_unicode_compatible from django.utils.safestring import SafeData Loading Loading @@ -125,12 +123,6 @@ class DefaultFiltersTests(TestCase): escapejs_filter('paragraph separator:\u2029and line separator:\u2028'), 'paragraph separator:\\u2029and line separator:\\u2028') def test_fix_ampersands(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", RemovedInDjango18Warning) self.assertEqual(fix_ampersands_filter('Jack & Jill & Jeroboam'), 'Jack & Jill & Jeroboam') def test_linenumbers(self): self.assertEqual(linenumbers('line 1\nline 2'), '1. line 1\n2. line 2') Loading
tests/template_tests/filters.py +0 −5 Original line number Diff line number Diff line Loading @@ -104,11 +104,6 @@ def get_filter_tests(): 'filter-capfirst01': ("{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"), 'filter-capfirst02': ("{{ a|capfirst }} {{ b|capfirst }}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"), # Note that applying fix_ampsersands in autoescape mode leads to # double escaping. 'filter-fix_ampersands01': ("{% autoescape off %}{{ a|fix_ampersands }} {{ b|fix_ampersands }}{% endautoescape %}", {"a": "a&b", "b": mark_safe("a&b")}, "a&b a&b"), 'filter-fix_ampersands02': ("{{ a|fix_ampersands }} {{ b|fix_ampersands }}", {"a": "a&b", "b": mark_safe("a&b")}, "a&amp;b a&b"), 'filter-floatformat01': ("{% autoescape off %}{{ a|floatformat }} {{ b|floatformat }}{% endautoescape %}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"), 'filter-floatformat02': ("{{ a|floatformat }} {{ b|floatformat }}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"), Loading