Django

Code

Changeset 6911

Show
Ignore:
Timestamp:
12/10/07 23:49:11 (1 year ago)
Author:
gwilson
Message:

Minor style fixes.

Files:

Legend:

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

    r6856 r6911  
    1 "HTML utilities suitable for global use.
     1"""HTML utilities suitable for global use.""
    22 
    33import re 
     
    99from django.utils.http import urlquote 
    1010 
    11 # Configuration for urlize() function 
     11# Configuration for urlize() function. 
    1212LEADING_PUNCTUATION  = ['(', '<', '&lt;'] 
    1313TRAILING_PUNCTUATION = ['.', ',', ')', '>', '\n', '&gt;'] 
    1414 
    15 # list of possible strings used for bullets in bulleted lists 
     15# List of possible strings used for bullets in bulleted lists. 
    1616DOTS = ['&middot;', '*', '\xe2\x80\xa2', '&#149;', '&bull;', '&#8226;'] 
    1717 
     
    2929 
    3030def escape(html): 
    31     "Return the given HTML with ampersands, quotes and carets encoded.
     31    """Returns the given HTML with ampersands, quotes and carets encoded.""
    3232    return mark_safe(force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')) 
    3333escape = allow_lazy(escape, unicode) 
     
    4343 
    4444def linebreaks(value, autoescape=False): 
    45     "Converts newlines into <p> and <br />s
     45    """Converts newlines into <p> and <br />s.""
    4646    value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines 
    4747    paras = re.split('\n{2,}', value) 
     
    5151        paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] 
    5252    return u'\n\n'.join(paras) 
    53 linebreaks = allow_lazy(linebreaks, unicode)  
     53linebreaks = allow_lazy(linebreaks, unicode) 
    5454 
    5555def strip_tags(value): 
    56     "Return the given HTML with all tags stripped.
     56    """Returns the given HTML with all tags stripped.""
    5757    return re.sub(r'<[^>]*?>', '', force_unicode(value)) 
    5858strip_tags = allow_lazy(strip_tags) 
    5959 
    6060def strip_spaces_between_tags(value): 
    61     "Return the given HTML with spaces between tags removed.
     61    """Returns the given HTML with spaces between tags removed.""
    6262    return re.sub(r'>\s+<', '><', force_unicode(value)) 
    6363strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode) 
    6464 
    6565def strip_entities(value): 
    66     "Return the given HTML with all entities (&something;) stripped.
     66    """Returns the given HTML with all entities (&something;) stripped.""
    6767    return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value)) 
    6868strip_entities = allow_lazy(strip_entities, unicode) 
    6969 
    7070def fix_ampersands(value): 
    71     "Return the given HTML with all unencoded ampersands encoded correctly.
     71    """Returns the given HTML with all unencoded ampersands encoded correctly.""
    7272    return unencoded_ampersands_re.sub('&amp;', force_unicode(value)) 
    7373fix_ampersands = allow_lazy(fix_ampersands, unicode) 
     
    7575def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): 
    7676    """ 
    77     Convert any URLs in text into clickable links. 
     77    Converts any URLs in text into clickable links. 
    7878 
    7979    Works on http://, https://, and www. links.  Links can have trailing