File: //lib/python3/dist-packages/twisted/web/_auth/__pycache__/wrapper.cpython-38.pyc
U
��W[v! � @ s� d Z ddlmZmZ ddlmZ ddlmZ ddlm Z ddl
mZ ddlm
Z
ddlmZmZ dd lmZ dd
lmZ ee�G dd� de��Zee�G d
d� de��ZdS )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.
� )�absolute_import�division)�error)� Anonymous)�unicode)�proxyForInterface)�util)� ErrorPage� IResource)�Logger)�implementerc @ s, e Zd ZdZdZdd� Zdd� Zdd� Zd S )
�UnauthorizedResourcez6
Simple IResource to escape Resource dispatch
Tc C s
|| _ d S �N)�_credentialFactories)�selfZ 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 krbd
S dS )z=
Send www-authenticate headers to the client
c S s t | t�r| �d�S | S )N�ascii)�
isinstancer �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�l�k�v�r �quoteStringr r �generateWWWAuthenticate0 s z<UnauthorizedResource.render.<locals>.generateWWWAuthenticatec S s d| � dd�� dd� d S )N� "� \s \\s \")�replacer r r r r% 8 s z0UnauthorizedResource.render.<locals>.quoteStringi� s www-authenticates HEAD� s Unauthorized)ZsetResponseCoder ZgetChallengeZresponseHeadersZaddRawHeaderr �method)r �requestr&