~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/middleware/common.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        # Append a slash if APPEND_SLASH is set and the URL doesn't have a
54
54
        # trailing slash and there is no pattern for the current path
55
55
        if settings.APPEND_SLASH and (not old_url[1].endswith('/')):
56
 
            if (not _is_valid_path(request.path_info) and
57
 
                    _is_valid_path("%s/" % request.path_info)):
 
56
            urlconf = getattr(request, 'urlconf', None)
 
57
            if (not _is_valid_path(request.path_info, urlconf) and
 
58
                    _is_valid_path("%s/" % request.path_info, urlconf)):
58
59
                new_url[1] = new_url[1] + '/'
59
60
                if settings.DEBUG and request.method == 'POST':
60
61
                    raise RuntimeError, (""
130
131
    # Different subdomains are treated as different domains.
131
132
    return referer is not None and re.match("^https?://%s/" % re.escape(domain), referer)
132
133
 
133
 
def _is_valid_path(path):
 
134
def _is_valid_path(path, urlconf=None):
134
135
    """
135
136
    Returns True if the given path resolves against the default URL resolver,
136
137
    False otherwise.
139
140
    easier, avoiding unnecessarily indented try...except blocks.
140
141
    """
141
142
    try:
142
 
        urlresolvers.resolve(path)
 
143
        urlresolvers.resolve(path, urlconf)
143
144
        return True
144
145
    except urlresolvers.Resolver404:
145
146
        return False