
    k"g,                         d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ  G d d      Z G d	 d
e      Z G d de      Z G d de      Zy)    )urlparse)settings)REDIRECT_FIELD_NAME)redirect_to_login)ImproperlyConfiguredPermissionDenied)resolve_urlc                   8    e Zd ZdZdZdZdZeZd Z	d Z
d Zd Zy)	AccessMixinz^
    Abstract CBV mixin that gives access mixins the same customizable
    functionality.
    N Fc                     | j                   xs t        j                  }|sPt        | j                  j
                   d| j                  j
                   d| j                  j
                   d      t        |      S )zK
        Override this method to override the login_url attribute.
        z, is missing the login_url attribute. Define z,.login_url, settings.LOGIN_URL, or override z.get_login_url().)	login_urlr   	LOGIN_URLr   	__class____name__str)selfr   s     S/var/www/html/djangosite/lib/python3.12/site-packages/django/contrib/auth/mixins.pyget_login_urlzAccessMixin.get_login_url   sr     NN8h&8&8	&>>**++W>>**++W>>**++<> 
 9~    c                     | j                   S )z[
        Override this method to override the permission_denied_message attribute.
        )permission_denied_messager   s    r   get_permission_denied_messagez)AccessMixin.get_permission_denied_message"   s     ---r   c                     | j                   S )zU
        Override this method to override the redirect_field_name attribute.
        )redirect_field_namer   s    r   get_redirect_field_namez#AccessMixin.get_redirect_field_name(   s     '''r   c                    | j                   s | j                  j                  j                  rt	        | j                               | j                  j                         }t        | j                               }t        |      d d \  }}t        |      d d \  }}|r||k(  r!|r||k(  r| j                  j                         }t        ||| j                               S )N   )raise_exceptionrequestuseris_authenticatedr   r   build_absolute_urir	   r   r   get_full_pathr   r   )r   pathresolved_login_urllogin_schemelogin_netloccurrent_schemecurrent_netlocs          r   handle_no_permissionz AccessMixin.handle_no_permission.   s    4<<#4#4#E#E"4#E#E#GHH||..0(););)=> &..@%A"1%E"l)1$);& > ><<--/D ((*
 	
r   )r   
__module____qualname____doc__r   r   r    r   r   r   r   r   r,    r   r   r   r   
   s3    
 I "O-.(
r   r   c                   "     e Zd ZdZ fdZ xZS )LoginRequiredMixinz.Verify that the current user is authenticated.c                 v    |j                   j                  s| j                         S t        |   |g|i |S N)r"   r#   r,   superdispatchr   r!   argskwargsr   s       r   r6   zLoginRequiredMixin.dispatchF   s9    ||,,,,..w9$9&99r   )r   r-   r.   r/   r6   __classcell__r   s   @r   r2   r2   C   s    8: :r   r2   c                   2     e Zd ZdZdZd Zd Z fdZ xZS )PermissionRequiredMixinz;Verify that the current user has all specified permissions.Nc                 (   | j                   Pt        | j                  j                   d| j                  j                   d| j                  j                   d      t	        | j                   t
              r| j                   f}|S | j                   }|S )zv
        Override this method to override the permission_required attribute.
        Must return an iterable.
        z6 is missing the permission_required attribute. Define z".permission_required, or override z.get_permission_required().)permission_requiredr   r   r   
isinstancer   r   permss     r   get_permission_requiredz/PermissionRequiredMixin.get_permission_requiredQ   s    
 ##+&>>**+ ,9>>**++M>>**++FH  d..4--/E  ,,Er   c                 l    | j                         }| j                  j                  j                  |      S )zT
        Override this method to customize the way permissions are checked.
        )rC   r!   r"   	has_permsrA   s     r   has_permissionz&PermissionRequiredMixin.has_permissionc   s-     ,,.||  **511r   c                 j    | j                         s| j                         S t        |   |g|i |S r4   )rF   r,   r5   r6   r7   s       r   r6   z PermissionRequiredMixin.dispatchj   s8    ""$,,..w9$9&99r   )	r   r-   r.   r/   r?   rC   rF   r6   r:   r;   s   @r   r=   r=   L   s     E$2: :r   r=   c                   .     e Zd ZdZd Zd Z fdZ xZS )UserPassesTestMixinz]
    Deny a request with a permission error if the test_func() method returns
    False.
    c                 ^    t        dj                  | j                  j                              )Nz;{} is missing the implementation of the test_func() method.)NotImplementedErrorformatr   r   r   s    r   	test_funczUserPassesTestMixin.test_funcv   s*    !IPP''
 	
r   c                     | j                   S )zK
        Override this method to use a different test_func method.
        )rM   r   s    r   get_test_funcz!UserPassesTestMixin.get_test_func}   s     ~~r   c                 x     | j                                }|s| j                         S t        |   |g|i |S r4   )rO   r,   r5   r6   )r   r!   r8   r9   user_test_resultr   s        r   r6   zUserPassesTestMixin.dispatch   sC    /4--/1,,..w9$9&99r   )r   r-   r.   r/   rM   rO   r6   r:   r;   s   @r   rI   rI   p   s    

: :r   rI   N)urllib.parser   django.confr   django.contrib.authr   django.contrib.auth.viewsr   django.core.exceptionsr   r   django.shortcutsr	   r   r2   r=   rI   r0   r   r   <module>rX      sG    !   3 7 I (6
 6
r: :!:k !:H:+ :r   