Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cleaned up a couple unused imports and fixed docstrings to follow Pyt…

…hon Style Guide.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7aac81d28038dce5f1a250caa63cf5a86692be1c 1 parent f6ced03
Gary Wilson Jr. authored July 16, 2007

Showing 1 changed file with 22 additions and 21 deletions. Show diff stats Hide diff stats

  1. 43  django/utils/html.py
43  django/utils/html.py
@@ -2,8 +2,8 @@
2 2
 
3 3
 import re
4 4
 import string
5  
-import urllib
6  
-from django.utils.encoding import force_unicode, smart_str
  5
+
  6
+from django.utils.encoding import force_unicode
7 7
 from django.utils.functional import allow_lazy
8 8
 
9 9
 # Configuration for urlize() function
@@ -26,12 +26,12 @@
26 26
 del x # Temporary variable
27 27
 
28 28
 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."
30 30
     return force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
31 31
 escape = allow_lazy(escape, unicode)
32 32
 
33 33
 def linebreaks(value):
34  
-    "Converts newlines into <p> and <br />s"
  34
+    "Convert newlines into <p> and <br />s."
35 35
     value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines
36 36
     paras = re.split('\n{2,}', value)
37 37
     paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras]
@@ -39,31 +39,32 @@ def linebreaks(value):
39 39
 linebreaks = allow_lazy(linebreaks, unicode)
40 40
 
41 41
 def strip_tags(value):
42  
-    "Returns the given HTML with all tags stripped"
  42
+    "Return the given HTML with all tags stripped."
43 43
     return re.sub(r'<[^>]*?>', '', force_unicode(value))
44 44
 strip_tags = allow_lazy(strip_tags)
45 45
 
46 46
 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."
48 48
     return re.sub(r'>\s+<', '><', force_unicode(value))
49 49
 strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode)
50 50
 
51 51
 def strip_entities(value):
52  
-    "Returns the given HTML with all entities (&something;) stripped"
  52
+    "Return the given HTML with all entities (&something;) stripped."
53 53
     return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value))
54 54
 strip_entities = allow_lazy(strip_entities, unicode)
55 55
 
56 56
 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."
58 58
     return unencoded_ampersands_re.sub('&amp;', force_unicode(value))
59 59
 fix_ampersands = allow_lazy(fix_ampersands, unicode)
60 60
 
61 61
 def urlize(text, trim_url_limit=None, nofollow=False):
62 62
     """
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.
67 68
 
68 69
     If trim_url_limit is not None, the URLs in link text longer than this limit
69 70
     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):
94 95
 
95 96
 def clean_html(text):
96 97
     """
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
102 103
           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
105 106
           bottom of the text.
106 107
     """
107 108
     from django.utils.text import normalize_newlines
@@ -120,8 +121,8 @@ def replace_p_tags(match):
120 121
             s = s.replace('<p>%s' % d, '<li>')
121 122
         return u'<ul>\n%s\n</ul>' % s
122 123
     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.
124 126
     text = trailing_empty_content_re.sub('', text)
125 127
     return text
126 128
 clean_html = allow_lazy(clean_html, unicode)
127  
-

0 notes on commit 7aac81d

Please sign in to comment.
Something went wrong with that request. Please try again.