Django

Code

Changeset 5717

Show
Ignore:
Timestamp:
07/16/07 00:28:13 (1 year ago)
Author:
gwilson
Message:

Cleaned up a couple unused imports and fixed docstrings to follow Python Style Guide.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/html.py

    r5701 r5717  
    33import re 
    44import string 
    5 import urllib 
    6 from django.utils.encoding import force_unicode, smart_str 
     5 
     6from django.utils.encoding import force_unicode 
    77from django.utils.functional import allow_lazy 
    88 
     
    2727 
    2828def 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;') 
    3131escape = allow_lazy(escape, unicode) 
    3232 
    3333def 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) 
     
    4040 
    4141def 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)) 
    4444strip_tags = allow_lazy(strip_tags) 
    4545 
    4646def 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)) 
    4949strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode) 
    5050 
    5151def 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)) 
    5454strip_entities = allow_lazy(strip_entities, unicode) 
    5555 
    5656def 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)) 
    5959fix_ampersands = allow_lazy(fix_ampersands, unicode) 
     
    6161def 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 
     
    9596def 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    """ 
     
    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 
    126128clean_html = allow_lazy(clean_html, unicode) 
    127