Skip to content

Commit 7aac81d

Browse files
committed
Cleaned up a couple unused imports and fixed docstrings to follow Python Style Guide.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent f6ced03 commit 7aac81d

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

django/utils/html.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import re
44
import string
5-
import urllib
6-
from django.utils.encoding import force_unicode, smart_str
5+
6+
from django.utils.encoding import force_unicode
77
from django.utils.functional import allow_lazy
88

99
# Configuration for urlize() function
@@ -26,44 +26,45 @@
2626
del x # Temporary variable
2727

2828
def escape(html):
29-
"Returns the given HTML with ampersands, quotes and carets encoded"
29+
"Return the given HTML with ampersands, quotes and carets encoded."
3030
return force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
3131
escape = allow_lazy(escape, unicode)
3232

3333
def linebreaks(value):
34-
"Converts newlines into <p> and <br />s"
34+
"Convert newlines into <p> and <br />s."
3535
value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines
3636
paras = re.split('\n{2,}', value)
3737
paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
3838
return u'\n\n'.join(paras)
3939
linebreaks = allow_lazy(linebreaks, unicode)
4040

4141
def strip_tags(value):
42-
"Returns the given HTML with all tags stripped"
42+
"Return the given HTML with all tags stripped."
4343
return re.sub(r'<[^>]*?>', '', force_unicode(value))
4444
strip_tags = allow_lazy(strip_tags)
4545

4646
def strip_spaces_between_tags(value):
47-
"Returns the given HTML with spaces between tags removed"
47+
"Return the given HTML with spaces between tags removed."
4848
return re.sub(r'>\s+<', '><', force_unicode(value))
4949
strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode)
5050

5151
def strip_entities(value):
52-
"Returns the given HTML with all entities (&something;) stripped"
52+
"Return the given HTML with all entities (&something;) stripped."
5353
return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value))
5454
strip_entities = allow_lazy(strip_entities, unicode)
5555

5656
def fix_ampersands(value):
57-
"Returns the given HTML with all unencoded ampersands encoded correctly"
57+
"Return the given HTML with all unencoded ampersands encoded correctly."
5858
return unencoded_ampersands_re.sub('&amp;', force_unicode(value))
5959
fix_ampersands = allow_lazy(fix_ampersands, unicode)
6060

6161
def urlize(text, trim_url_limit=None, nofollow=False):
6262
"""
63-
Converts any URLs in text into clickable links. Works on http://, https://
64-
and www. links. Links can have trailing punctuation (periods, commas,
65-
close-parens) and leading punctuation (opening parens) and it'll still do
66-
the right thing.
63+
Convert any URLs in text into clickable links.
64+
65+
Works on http://, https://, and www. links. Links can have trailing
66+
punctuation (periods, commas, close-parens) and leading punctuation
67+
(opening parens) and it'll still do the right thing.
6768
6869
If trim_url_limit is not None, the URLs in link text longer than this limit
6970
will truncated to trim_url_limit-3 characters and appended with an elipsis.
@@ -94,14 +95,14 @@ def urlize(text, trim_url_limit=None, nofollow=False):
9495

9596
def clean_html(text):
9697
"""
97-
Cleans the given HTML. Specifically, it does the following:
98-
* Converts <b> and <i> to <strong> and <em>.
99-
* Encodes all ampersands correctly.
100-
* Removes all "target" attributes from <a> tags.
101-
* Removes extraneous HTML, such as presentational tags that open and
98+
Clean the given HTML. Specifically, do the following:
99+
* Convert <b> and <i> to <strong> and <em>.
100+
* Encode all ampersands correctly.
101+
* Remove all "target" attributes from <a> tags.
102+
* Remove extraneous HTML, such as presentational tags that open and
102103
immediately close and <br clear="all">.
103-
* Converts hard-coded bullets into HTML unordered lists.
104-
* Removes stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
104+
* Convert hard-coded bullets into HTML unordered lists.
105+
* Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
105106
bottom of the text.
106107
"""
107108
from django.utils.text import normalize_newlines
@@ -120,8 +121,8 @@ def replace_p_tags(match):
120121
s = s.replace('<p>%s' % d, '<li>')
121122
return u'<ul>\n%s\n</ul>' % s
122123
text = hard_coded_bullets_re.sub(replace_p_tags, text)
123-
# Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the bottom of the text.
124+
# Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the bottom
125+
# of the text.
124126
text = trailing_empty_content_re.sub('', text)
125127
return text
126128
clean_html = allow_lazy(clean_html, unicode)
127-

0 commit comments

Comments
 (0)