PageRenderTime 212ms CodeModel.GetById 81ms app.highlight 4ms RepoModel.GetById 56ms app.codeStats 11ms

/django/conf/urls/defaults.py

https://code.google.com/p/mango-py/
Python | 42 lines | 35 code | 5 blank | 2 comment | 6 complexity | 7ce1c372eaac925667f42a7cac93fcd5 MD5 | raw file
 1from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
 2from django.core.exceptions import ImproperlyConfigured
 3
 4__all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
 5
 6handler404 = 'django.views.defaults.page_not_found'
 7handler500 = 'django.views.defaults.server_error'
 8
 9def include(arg, namespace=None, app_name=None):
10    if isinstance(arg, tuple):
11        # callable returning a namespace hint
12        if namespace:
13            raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
14        urlconf_module, app_name, namespace = arg
15    else:
16        # No namespace hint - use manually provided namespace
17        urlconf_module = arg
18    return (urlconf_module, app_name, namespace)
19
20def patterns(prefix, *args):
21    pattern_list = []
22    for t in args:
23        if isinstance(t, (list, tuple)):
24            t = url(prefix=prefix, *t)
25        elif isinstance(t, RegexURLPattern):
26            t.add_prefix(prefix)
27        pattern_list.append(t)
28    return pattern_list
29
30def url(regex, view, kwargs=None, name=None, prefix=''):
31    if isinstance(view, (list,tuple)):
32        # For include(...) processing.
33        urlconf_module, app_name, namespace = view
34        return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace)
35    else:
36        if isinstance(view, basestring):
37            if not view:
38                raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex)
39            if prefix:
40                view = prefix + '.' + view
41        return RegexURLPattern(regex, view, kwargs, name)
42