File: //usr/lib/python3/dist-packages/twisted/web/_auth/__pycache__/wrapper.cpython-310.pyc
o
�b�! � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZmZ ee�G d d
� d
��Zee�G dd� d��Zd
S )a�
A guard implementation which supports HTTP header-based authentication
schemes.
If no I{Authorization} header is supplied, an anonymous login will be
attempted by using a L{Anonymous} credentials object. If such a header is
supplied and does not contain allowed credentials, or if anonymous login is
denied, a 401 will be sent in the response along with I{WWW-Authenticate}
headers for each of the allowed authentication schemes.
� )�implementer)�error)� Anonymous)�Logger)�proxyForInterface)�util)� ErrorPage� IResourcec @ s4 e Zd ZdZdZdd� Zdd� Zdd� Zd d
� ZdS )�UnauthorizedResourcez6
Simple IResource to escape Resource dispatch
Tc C s
|| _ d S �N)�_credentialFactories)�self� factories� r �;/usr/lib/python3/dist-packages/twisted/web/_auth/wrapper.py�__init__# s
zUnauthorizedResource.__init__c sf dd� � � �fdd�}dd� �|� d� | jD ]}|�|�}|j�d||j|�� q|jd kr1d
S dS )z=
Send www-authenticate headers to the client
c S s t | t�r
| �d�S | S )N�ascii)�
isinstance�str�encode��sr r r �ensureBytes+ s z0UnauthorizedResource.render.<locals>.ensureBytesc sP g }|� � D ]\}}� |�}� |�}|�|d �|� � qd�| d�|�g�S )N� =� s , )�items�append�join)�scheme� challenge�lst�k�v�r �quoteStringr r �generateWWWAuthenticate. s z<UnauthorizedResource.render.<locals>.generateWWWAuthenticatec S s d| � dd�� dd� d S )N� "� \s \\s \")�replacer r r r r$ 6 s z0UnauthorizedResource.render.<locals>.quoteStringi� s www-authenticates HEAD� s Unauthorized)�setResponseCoder �getChallenge�responseHeaders�addRawHeaderr �method)r
�requestr% �factr r r# r �render&