
    $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	 d dl
mZ d dlmZ d dlmZ  G d	 d
          ZdS )    )quote)apps)settings)messages)MessageFailure)redirect)SocialAuthBaseException)social_loggerc                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	SocialAuthExceptionMiddlewarea  Middleware that handles Social Auth AuthExceptions by providing the user
    with a message, logging an error, and redirecting to some next location.

    By default, the exception message itself is sent to the user and they are
    redirected to the location specified in the SOCIAL_AUTH_LOGIN_ERROR_URL
    setting.

    This middleware can be extended by overriding the get_message or
    get_redirect_uri methods, which each accept request and exception.
    c                     || _         d S Nget_response)selfr   s     X/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/social_django/middleware.py__init__z&SocialAuthExceptionMiddleware.__init__   s    (    c                 ,    |                      |          S r   r   )r   requests     r   __call__z&SocialAuthExceptionMiddleware.__call__   s      )))r   c                 ^   t          |dd           }||                     ||          rd S t          |t                    rt          |dd           }t          |dd          }|                     ||          }|                     ||          }t          j        d          rct          j	        |           	 t          j        ||d|            nG# t          $ r& |r!|d|v rd	pdd
t          |           d| z   z  }Y nw xY wt          j        |           |rt          |          S d S d S )Nsocial_strategybackendnamezunknown-backendzdjango.contrib.messageszsocial-auth )
extra_tags?&zmessage=z	&backend=)getattrraise_exception
isinstancer	   get_messageget_redirect_urir   is_installedr
   infor   errorr   r   r   )r   r   	exceptionstrategyr   backend_namemessageurls           r   process_exceptionz/SocialAuthExceptionMiddleware.process_exception   s   7$5t<<t33GYGGFi!899 	%gy$77G"7F4EFFL&&w	::G'';;C !:;; -"7+++ON5RL5R5R     & O O O O3J.35#NuW~~NNNN O OO #G,,, %}}$-	% 	%*% %s   8C -DDc                 l    t          |dd           }| |                    dt          j                  S d S )Nr   RAISE_EXCEPTIONS)r   settingr   DEBUGr   r   r'   r(   s       r   r    z-SocialAuthExceptionMiddleware.raise_exception;   s;    7$5t<<##$6GGG  r   c                      t          |          S r   )str)r   r   r'   s      r   r"   z)SocialAuthExceptionMiddleware.get_message@   s    9~~r   c                 N    t          |dd           }|                    d          S )Nr   LOGIN_ERROR_URL)r   r/   r1   s       r   r#   z.SocialAuthExceptionMiddleware.get_redirect_uriC   s)    7$5t<< 1222r   N)
__name__
__module____qualname____doc__r   r   r,   r    r"   r#    r   r   r   r      s{        	 	) ) )* * *% % %:H H H
  3 3 3 3 3r   r   N)urllib.parser   django.appsr   django.confr   django.contribr   django.contrib.messages.apir   django.shortcutsr   social_core.exceptionsr	   social_core.utilsr
   r   r:   r   r   <module>rC      s                            # # # # # # 6 6 6 6 6 6 % % % % % % : : : : : : + + + + + +93 93 93 93 93 93 93 93 93 93r   