Ticket #7537: dj-urlresolver-patch1.patch

File dj-urlresolver-patch1.patch, 1.9 KB (added by Kenneth Arnold, 16 years ago)

nearly minimal patch

  • urlresolvers.py

     
    206206        self.urlconf_name = urlconf_name
    207207        self.callback = None
    208208        self.default_kwargs = default_kwargs or {}
    209         self._reverse_dict = {}
    210209
    211210    def __repr__(self):
    212211        return '<%s %s %s>' % (self.__class__.__name__, self.urlconf_name, self.regex.pattern)
    213212
    214213    def _get_reverse_dict(self):
    215         if not self._reverse_dict and hasattr(self.urlconf_module, 'urlpatterns'):
    216             for pattern in reversed(self.urlconf_module.urlpatterns):
     214        if not hasattr(self, '_reverse_dict'):
     215            # FIXME: now we'll fail if no URL patterns are defined. I
     216            # think that's a good thing, though.
     217            # Was: and hasattr(self.urlconf_module, 'urlpatterns'):
     218            self._reverse_dict = {}
     219            for pattern in reversed(self.get_url_patterns()):
    217220                if isinstance(pattern, RegexURLResolver):
    218221                    for key, value in pattern.reverse_dict.iteritems():
    219222                        self._reverse_dict[key] = (pattern,) + value
     
    228231        match = self.regex.search(path)
    229232        if match:
    230233            new_path = path[match.end():]
    231             for pattern in self.urlconf_module.urlpatterns:
     234            for pattern in self.get_url_patterns():
    232235                try:
    233236                    sub_match = pattern.resolve(new_path)
    234237                except Resolver404, e:
     
    256259            return self._urlconf_module
    257260    urlconf_module = property(_get_urlconf_module)
    258261
    259     def _get_url_patterns(self):
     262    def get_url_patterns(self):
    260263        return self.urlconf_module.urlpatterns
    261     url_patterns = property(_get_url_patterns)
    262264
    263265    def _resolve_special(self, view_type):
    264266        callback = getattr(self.urlconf_module, 'handler%s' % view_type)
Back to Top