Ticket #15635: new_style_raise_in_docs.patch

File new_style_raise_in_docs.patch, 6.4 KB (added by Daniel Duan, 14 years ago)
  • django/middleware/common.py

    From 5d425b36bf8cacc2ac84c84d89084a889d7b1b1a Mon Sep 17 00:00:00 2001
    From: DaNmarner <danmarner@gmail.com>
    Date: Thu, 17 Mar 2011 12:06:14 -0500
    Subject: [PATCH] Made raise in docs the new style
    
    ---
     django/middleware/common.py         |    4 ++--
     django/utils/unittest/case.py       |    2 +-
     docs/howto/custom-template-tags.txt |   14 +++++++-------
     docs/ref/templates/api.txt          |    2 +-
     docs/topics/forms/formsets.txt      |    2 +-
     5 files changed, 12 insertions(+), 12 deletions(-)
    
    diff --git a/django/middleware/common.py b/django/middleware/common.py
    index 07c6ff6..2252c8f 100644
    a b class CommonMiddleware(object):  
    6868                    _is_valid_path("%s/" % request.path_info, urlconf)):
    6969                new_url[1] = new_url[1] + '/'
    7070                if settings.DEBUG and request.method == 'POST':
    71                     raise RuntimeError, (""
     71                    raise RuntimeError((""
    7272                    "You called this URL via POST, but the URL doesn't end "
    7373                    "in a slash and you have APPEND_SLASH set. Django can't "
    7474                    "redirect to the slash URL while maintaining POST data. "
    7575                    "Change your form to point to %s%s (note the trailing "
    7676                    "slash), or set APPEND_SLASH=False in your Django "
    77                     "settings.") % (new_url[0], new_url[1])
     77                    "settings.") % (new_url[0], new_url[1]))
    7878
    7979        if new_url == old_url:
    8080            # No redirects required.
  • django/utils/unittest/case.py

    diff --git a/django/utils/unittest/case.py b/django/utils/unittest/case.py
    index 8d943e2..e284800 100644
    a b class TestCase(unittest.TestCase):  
    997997                excName = expected_exception.__name__
    998998            else:
    999999                excName = str(expected_exception)
    1000             raise self.failureException, "%s not raised" % excName
     1000            raise self.failureException("%s not raised" % excName)
    10011001
    10021002
    10031003    def assertRegexpMatches(self, text, expected_regexp, msg=None):
  • docs/howto/custom-template-tags.txt

    diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
    index ec4cd35..7dc6cce 100644
    a b object::  
    351351            # split_contents() knows not to split quoted strings.
    352352            tag_name, format_string = token.split_contents()
    353353        except ValueError:
    354             raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0]
     354            raise template.TemplateSyntaxError("%r tag requires a single argument" % token.contents.split()[0])
    355355        if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
    356             raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
     356            raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name)
    357357        return CurrentTimeNode(format_string[1:-1])
    358358
    359359Notes:
    Now your tag should begin to look like this::  
    596596            # split_contents() knows not to split quoted strings.
    597597            tag_name, date_to_be_formatted, format_string = token.split_contents()
    598598        except ValueError:
    599             raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents.split()[0]
     599            raise template.TemplateSyntaxError("%r tag requires exactly two arguments" % token.contents.split()[0])
    600600        if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
    601             raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
     601            raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name)
    602602        return FormatTimeNode(date_to_be_formatted, format_string[1:-1])
    603603
    604604You also have to change the renderer to retrieve the actual contents of the
    class, like so::  
    863863            # Splitting by None == splitting by spaces.
    864864            tag_name, arg = token.contents.split(None, 1)
    865865        except ValueError:
    866             raise template.TemplateSyntaxError, "%r tag requires arguments" % token.contents.split()[0]
     866            raise template.TemplateSyntaxError("%r tag requires arguments" % token.contents.split()[0])
    867867        m = re.search(r'(.*?) as (\w+)', arg)
    868868        if not m:
    869             raise template.TemplateSyntaxError, "%r tag had invalid arguments" % tag_name
     869            raise template.TemplateSyntaxError("%r tag had invalid arguments" % tag_name)
    870870        format_string, var_name = m.groups()
    871871        if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
    872             raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
     872            raise template.TemplateSyntaxError("%r tag's argument should be in quotes" % tag_name)
    873873        return CurrentTimeNode3(format_string[1:-1], var_name)
    874874
    875875The difference here is that ``do_current_time()`` grabs the format string and
  • docs/ref/templates/api.txt

    diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
    index ba78f15..4cfa4da 100644
    a b straight lookups. Here are some things to keep in mind:  
    170170        >>> t = Template("My name is {{ person.first_name }}.")
    171171        >>> class PersonClass3:
    172172        ...     def first_name(self):
    173         ...         raise AssertionError, "foo"
     173        ...         raise AssertionError("foo")
    174174        >>> p = PersonClass3()
    175175        >>> t.render(Context({"person": p}))
    176176        Traceback (most recent call last):
  • docs/topics/forms/formsets.txt

    diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt
    index 41438f2..a3721fd 100644
    a b is where you define your own validation that works at the formset level::  
    216216    ...             form = self.forms[i]
    217217    ...             title = form.cleaned_data['title']
    218218    ...             if title in titles:
    219     ...                 raise forms.ValidationError, "Articles in a set must have distinct titles."
     219    ...                 raise forms.ValidationError("Articles in a set must have distinct titles.")
    220220    ...             titles.append(title)
    221221
    222222    >>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet)
Back to Top