diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-12-19 05:08:37 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-12-19 05:08:37 +0000 |
| commit | 97091940b1efbc6018133e9f77402c2983fa702f (patch) | |
| tree | e003a3ec00ab4b0bd0cda7799485cedbf787cd31 /django/utils | |
| parent | 13d3162aaf7fce11c06d447f397e32b7648ae199 (diff) | |
queryset-refactor: Merged from trunk up to [6953].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6954 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/html.py | 22 | ||||
| -rw-r--r-- | django/utils/maxlength.py | 18 |
2 files changed, 19 insertions, 21 deletions
diff --git a/django/utils/html.py b/django/utils/html.py index 34bbf7357f..33e2ee3856 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -1,4 +1,4 @@ -"HTML utilities suitable for global use." +"""HTML utilities suitable for global use.""" import re import string @@ -8,11 +8,11 @@ from django.utils.encoding import force_unicode from django.utils.functional import allow_lazy from django.utils.http import urlquote -# Configuration for urlize() function +# Configuration for urlize() function. LEADING_PUNCTUATION = ['(', '<', '<'] TRAILING_PUNCTUATION = ['.', ',', ')', '>', '\n', '>'] -# list of possible strings used for bullets in bulleted lists +# List of possible strings used for bullets in bulleted lists. DOTS = ['·', '*', '\xe2\x80\xa2', '•', '•', '•'] unencoded_ampersands_re = re.compile(r'&(?!(\w+|#\d+);)') @@ -28,7 +28,7 @@ trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\ del x # Temporary variable def escape(html): - "Return the given HTML with ampersands, quotes and carets encoded." + """Returns the given HTML with ampersands, quotes and carets encoded.""" return mark_safe(force_unicode(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')) escape = allow_lazy(escape, unicode) @@ -42,7 +42,7 @@ def conditional_escape(html): return escape(html) def linebreaks(value, autoescape=False): - "Converts newlines into <p> and <br />s" + """Converts newlines into <p> and <br />s.""" value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines paras = re.split('\n{2,}', value) if autoescape: @@ -50,31 +50,31 @@ def linebreaks(value, autoescape=False): else: paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] return u'\n\n'.join(paras) -linebreaks = allow_lazy(linebreaks, unicode) +linebreaks = allow_lazy(linebreaks, unicode) def strip_tags(value): - "Return the given HTML with all tags stripped." + """Returns the given HTML with all tags stripped.""" return re.sub(r'<[^>]*?>', '', force_unicode(value)) strip_tags = allow_lazy(strip_tags) def strip_spaces_between_tags(value): - "Return the given HTML with spaces between tags removed." + """Returns the given HTML with spaces between tags removed.""" return re.sub(r'>\s+<', '><', force_unicode(value)) strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode) def strip_entities(value): - "Return the given HTML with all entities (&something;) stripped." + """Returns the given HTML with all entities (&something;) stripped.""" return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value)) strip_entities = allow_lazy(strip_entities, unicode) def fix_ampersands(value): - "Return the given HTML with all unencoded ampersands encoded correctly." + """Returns the given HTML with all unencoded ampersands encoded correctly.""" return unencoded_ampersands_re.sub('&', force_unicode(value)) fix_ampersands = allow_lazy(fix_ampersands, unicode) def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): """ - Convert any URLs in text into clickable links. + Converts any URLs in text into clickable links. Works on http://, https://, and www. links. Links can have trailing punctuation (periods, commas, close-parens) and leading punctuation diff --git a/django/utils/maxlength.py b/django/utils/maxlength.py index 1df6a3e93e..a616541f85 100644 --- a/django/utils/maxlength.py +++ b/django/utils/maxlength.py @@ -1,6 +1,6 @@ """ Utilities for providing backwards compatibility for the maxlength argument, -which has been replaced by max_length, see ticket #2101. +which has been replaced by max_length. See ticket #2101. """ from warnings import warn @@ -15,17 +15,15 @@ def legacy_maxlength(max_length, maxlength): """ Consolidates max_length and maxlength, providing backwards compatibilty for the legacy "maxlength" argument. + If one of max_length or maxlength is given, then that value is returned. - If both are given, a TypeError is raised. - If maxlength is used at all, a deprecation warning is issued. + If both are given, a TypeError is raised. If maxlength is used at all, a + deprecation warning is issued. """ if maxlength is not None: - warn("maxlength is deprecated, use max_length instead.", - DeprecationWarning, - stacklevel=3) + warn("maxlength is deprecated. Use max_length instead.", DeprecationWarning, stacklevel=3) if max_length is not None: - raise TypeError("field can not take both the max_length" - " argument and the legacy maxlength argument.") + raise TypeError("Field cannot take both the max_length argument and the legacy maxlength argument.") max_length = maxlength return max_length @@ -33,7 +31,8 @@ def remove_maxlength(func): """ A decorator to be used on a class's __init__ that provides backwards compatibilty for the legacy "maxlength" keyword argument, i.e. - name = models.CharField(maxlength=20) + name = models.CharField(maxlength=20) + It does this by changing the passed "maxlength" keyword argument (if it exists) into a "max_length" keyword argument. """ @@ -58,7 +57,6 @@ class LegacyMaxlength(type): Metaclass for providing backwards compatibility support for the "maxlength" keyword argument. """ - def __init__(cls, name, bases, attrs): super(LegacyMaxlength, cls).__init__(name, bases, attrs) # Decorate the class's __init__ to remove any maxlength keyword. |
