web/lib/django/contrib/auth/__init__.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
     1 import datetime
     1 import datetime
       
     2 from warnings import warn
     2 from django.core.exceptions import ImproperlyConfigured
     3 from django.core.exceptions import ImproperlyConfigured
     3 from django.utils.importlib import import_module
     4 from django.utils.importlib import import_module
     4 
     5 
     5 SESSION_KEY = '_auth_user_id'
     6 SESSION_KEY = '_auth_user_id'
     6 BACKEND_SESSION_KEY = '_auth_user_backend'
     7 BACKEND_SESSION_KEY = '_auth_user_backend'
    10     i = path.rfind('.')
    11     i = path.rfind('.')
    11     module, attr = path[:i], path[i+1:]
    12     module, attr = path[:i], path[i+1:]
    12     try:
    13     try:
    13         mod = import_module(module)
    14         mod = import_module(module)
    14     except ImportError, e:
    15     except ImportError, e:
    15         raise ImproperlyConfigured, 'Error importing authentication backend %s: "%s"' % (module, e)
    16         raise ImproperlyConfigured('Error importing authentication backend %s: "%s"' % (module, e))
    16     except ValueError, e:
    17     except ValueError, e:
    17         raise ImproperlyConfigured, 'Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?'
    18         raise ImproperlyConfigured('Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?')
    18     try:
    19     try:
    19         cls = getattr(mod, attr)
    20         cls = getattr(mod, attr)
    20     except AttributeError:
    21     except AttributeError:
    21         raise ImproperlyConfigured, 'Module "%s" does not define a "%s" authentication backend' % (module, attr)
    22         raise ImproperlyConfigured('Module "%s" does not define a "%s" authentication backend' % (module, attr))
       
    23     try:
       
    24         getattr(cls, 'supports_object_permissions')
       
    25     except AttributeError:
       
    26         warn("Authentication backends without a `supports_object_permissions` attribute are deprecated. Please define it in %s." % cls,
       
    27              PendingDeprecationWarning)
       
    28         cls.supports_object_permissions = False
       
    29     try:
       
    30         getattr(cls, 'supports_anonymous_user')
       
    31     except AttributeError:
       
    32         warn("Authentication backends without a `supports_anonymous_user` attribute are deprecated. Please define it in %s." % cls,
       
    33              PendingDeprecationWarning)
       
    34         cls.supports_anonymous_user = False
    22     return cls()
    35     return cls()
    23 
    36 
    24 def get_backends():
    37 def get_backends():
    25     from django.conf import settings
    38     from django.conf import settings
    26     backends = []
    39     backends = []