Ticket #3224: resolver.diff

File resolver.diff, 1.4 KB (added by mihai_preda@…, 18 years ago)

[patch] refactoring: remove code duplication between core.resolvers and core.handlers.base: added method to build a resolver in resolvers.py.

  • django/core/urlresolvers.py

     
    224224        result = reverse_helper(self.regex, *args, **kwargs)
    225225        return result + sub_match
    226226
    227 def resolve(path, urlconf=None):
     227def get_resolver(urlconf):
    228228    if urlconf is None:
    229229        from django.conf import settings
    230230        urlconf = settings.ROOT_URLCONF
    231231    resolver = RegexURLResolver(r'^/', urlconf)
    232     return resolver.resolve(path)
     232    return resolver
    233233
     234def resolve(path, urlconf=None):
     235    return get_resolver(urlconf).resolve(path)
     236
    234237def reverse(viewname, urlconf=None, args=None, kwargs=None):
    235238    args = args or []
    236239    kwargs = kwargs or {}
  • django/core/handlers/base.py

     
    6161                return response
    6262
    6363        # Get urlconf from request object, if available.  Otherwise use default.
    64         urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
     64        urlconf = getattr(request, "urlconf", None)
    6565
    66         resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
     66        resolver = urlresolvers.get_resolver(urlconf)
     67
    6768        try:
    6869            callback, callback_args, callback_kwargs = resolver.resolve(request.path)
    6970
Back to Top