ó
®â0_c           @  s•   d  d l  m Z d  d l m Z d  d l m Z e ƒ  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e f d	 „  ƒ  YZ
 d
 e
 f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literals(   t   get_user_model(   t
   Permissiont   ModelBackendc           B  sƒ   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 d d „ Z
 d d „ Z d d	 „ Z d
 „  Z d „  Z RS(   u9   
    Authenticates against settings.AUTH_USER_MODEL.
    c         K  s„   | d  k r! | j t j ƒ } n  y t j j | ƒ } Wn$ t j k
 r] t ƒ  j | ƒ n# X| j | ƒ r€ |  j	 | ƒ r€ | Sd  S(   N(
   t   Nonet   gett	   UserModelt   USERNAME_FIELDt   _default_managert   get_by_natural_keyt   DoesNotExistt   set_passwordt   check_passwordt   user_can_authenticate(   t   selft   requestt   usernamet   passwordt   kwargst   user(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   authenticate   s    c         C  s"   t  | d d ƒ } | p! | d k S(   u{   
        Reject users with is_active=False. Custom user models that don't have
        that attribute are allowed.
        u	   is_activeN(   t   getattrR   (   R   R   t	   is_active(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyR      s    c         C  s   | j  j ƒ  S(   N(   t   user_permissionst   all(   R   t   user_obj(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   _get_user_permissions#   s    c         C  s<   t  ƒ  j j d ƒ } d | j ƒ  } t j j i | | 6  S(   Nu   groupsu	   group__%s(   R   t   _metat	   get_fieldt   related_query_nameR   t   objectst   filter(   R   R   t   user_groups_fieldt   user_groups_query(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   _get_group_permissions&   s    c         C  s»   | j  s | j s | d k	 r& t ƒ  Sd | } t | | ƒ s® | j rZ t j j ƒ  } n t	 |  d | ƒ | ƒ } | j
 d d ƒ j ƒ  } t | | t d „  | Dƒ ƒ ƒ n  t	 | | ƒ S(   uâ   
        Returns the permissions of `user_obj` from `from_name`. `from_name` can
        be either "group" or "user" to return permissions from
        `_get_group_permissions` or `_get_user_permissions` respectively.
        u   _%s_perm_cacheu   _get_%s_permissionsu   content_type__app_labelu   codenamec         s  s%   |  ] \ } } d  | | f Vq d S(   u   %s.%sN(    (   t   .0t   ctt   name(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pys	   <genexpr>;   s    N(   R   t   is_anonymousR   t   sett   hasattrt   is_superuserR   R   R   R   t   values_listt   order_byt   setattr(   R   R   t   objt	   from_namet   perm_cache_namet   perms(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   _get_permissions+   s    
	#c         C  s   |  j  | | d ƒ S(   ut   
        Returns a set of permission strings the user `user_obj` has from their
        `user_permissions`.
        u   user(   R1   (   R   R   R-   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   get_user_permissions>   s    c         C  s   |  j  | | d ƒ S(   ur   
        Returns a set of permission strings the user `user_obj` has from the
        groups they belong.
        u   group(   R1   (   R   R   R-   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   get_group_permissionsE   s    c         C  sj   | j  s | j s | d  k	 r& t ƒ  St | d ƒ sc |  j | ƒ | _ | j j |  j | ƒ ƒ n  | j S(   Nu   _perm_cache(	   R   R&   R   R'   R(   R2   t   _perm_cachet   updateR3   (   R   R   R-   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   get_all_permissionsL   s    c         C  s#   | j  s t S| |  j | | ƒ k S(   N(   R   t   FalseR6   (   R   R   t   permR-   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   has_permT   s    	c         C  sH   | j  s t Sx4 |  j | ƒ D]# } | | j d ƒ  | k r t Sq Wt S(   uV   
        Returns True if user_obj has any permissions in the given app_label.
        u   .(   R   R7   R6   t   indext   True(   R   R   t	   app_labelR8   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   has_module_permsY   s    	c         C  sH   y t  j j d | ƒ } Wn t  j k
 r0 d  SX|  j | ƒ rD | Sd  S(   Nt   pk(   R   R   R   R
   R   R   (   R   t   user_idR   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   get_userd   s
    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R"   R1   R2   R3   R6   R9   R=   R@   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyR   	   s   					t   AllowAllUsersModelBackendc           B  s   e  Z d  „  Z RS(   c         C  s   t  S(   N(   R;   (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyR   m   s    (   RA   RB   R   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyRD   l   s   t   RemoteUserBackendc           B  s/   e  Z d  Z e Z d „  Z d „  Z d „  Z RS(   uÆ  
    This backend is to be used in conjunction with the ``RemoteUserMiddleware``
    found in the middleware module of this package, and is used when the server
    is handling authentication outside of Django.

    By default, the ``authenticate`` method creates ``User`` objects for
    usernames that don't already exist in the database.  Subclasses can disable
    this behavior by setting the ``create_unknown_user`` attribute to
    ``False``.
    c         C  s©   | s
 d Sd } |  j | ƒ } |  j re t j j i | t j 6  \ } } | r’ |  j | ƒ } q’ n- y t j j | ƒ } Wn t j	 k
 r‘ n X|  j
 | ƒ r¥ | Sd S(   u  
        The username passed as ``remote_user`` is considered trusted.  This
        method simply returns the ``User`` object with the given username,
        creating a new ``User`` object if ``create_unknown_user`` is ``True``.

        Returns None if ``create_unknown_user`` is ``False`` and a ``User``
        object with the given username is not found in the database.
        N(   R   t   clean_usernamet   create_unknown_userR   R   t   get_or_createR   t   configure_userR	   R
   R   (   R   R   t   remote_userR   R   t   created(    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyR   €   s    		c         C  s   | S(   uÉ   
        Performs any cleaning on the "username" prior to using it to get or
        create the user object.  Returns the cleaned username.

        By default, returns the username unchanged.
        (    (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyRF   ž   s    c         C  s   | S(   u‚   
        Configures a user after creation and returns the updated user.

        By default, returns the user unmodified.
        (    (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyRI   §   s    (   RA   RB   RC   R;   RG   R   RF   RI   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyRE   q   s
   
			t   AllowAllUsersRemoteUserBackendc           B  s   e  Z d  „  Z RS(   c         C  s   t  S(   N(   R;   (   R   R   (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyR   ±   s    (   RA   RB   R   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyRL   °   s   N(   t
   __future__R    t   django.contrib.authR   t   django.contrib.auth.modelsR   R   t   objectR   RD   RE   RL   (    (    (    s>   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/backends.pyt   <module>   s   	c?