At the moment BaseHandler is tied to RegexURLResolver. This makes it
impossible to change the urlresolver in a convenient way. (For the
mod_python handler it's easy, just extend the mod_python handler, but
for the development server you cannot change the handler) Thus django
core code must be altered (be it only in a marginal way) in order to
use a custom resolver.
My proposal is to introduce another setup setting, URL_RESOLVERS. And
allow for multiple resolvers to be defined here, so that third party
apps using the default resolver will still work even when using a
custom urlresolver. (Assuming, of course, that django resolver is not
removed from the settings). The custom resolvers must use the same
interface as the RegexResolver does, thus throw the same errors and
return the same stuff).
One issue is that the default django resolver needs be initiated.
Perhaps a custom urlresolver must be too.. The make this possible i
added the method create_resolver to the urlresolvers module. It
returns the regexresolver, and replaces the initiation currently done
in BaseHandler. (It's the same code, just in a different location)
To make things work i removed the default resolver from get_response
in BaseHandler and replaced it with:
[nothing changed]
# Try all resolvers...
# The first one is the preferred one, but if it fails, give
the subsequent ones a try
# Yet, if all routes fail, return the first
exception..
failed_resolve = True
failed_resolve_exception = False
for rslv in settings.URL_RESOLVERS:
try:
resolver = __import__(rslv , globals(), locals(),
["create_resolver"]).create_resolver(request)
callback, callback_args, callback_kwargs =
resolver.resolve(request.path)
except exceptions.PermissionDenied, e:
# Once forbidden stays forbidden
# I'm not sure whether this is always the most
suitable solution, after all
# in a differnt url setup an url could point to an
entirely different resource
# but i'm affraid to intruduce a potential security
risk when there is a rather
# naive urlsetup.
failed_resolve_exception = e
break
except Exception, e:
failed_resolve_exception = failed_resolve_exception or
e
else:
failed_resolve = False
break
try:
if failed_resolve: raise failed_resolve_exception
[nothing changed]
Considering the reluctance in changing the whole urlresolving thingy,
would such a patch be acceptable?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---