File: //opt/alt/python37/lib/python3.7/site-packages/paste/auth/__pycache__/basic.cpython-37.pyc
B
a�N� � @ sl d Z ddlmZ ddlT G dd� de�ZG dd� de�ZeZdgZdd � Z d
e
krhddlZejej
d� dS )
a�
Basic HTTP/1.0 Authentication
This module implements ``Basic`` authentication as described in
HTTP/1.0 specification [1]_ . Do not use this module unless you
are using SSL or need to work with very out-dated clients, instead
use ``digest`` authentication.
>>> from paste.wsgilib import dump_environ
>>> from paste.httpserver import serve
>>> # from paste.auth.basic import AuthBasicHandler
>>> realm = 'Test Realm'
>>> def authfunc(environ, username, password):
... return username == password
>>> serve(AuthBasicHandler(dump_environ, realm, authfunc))
serving on...
.. [1] http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#BasicAA
� )�HTTPUnauthorized)�*c @ s0 e Zd ZdZdZdd� Zdd� Zdd� ZeZd S )
�AuthBasicAuthenticatorz5
implements ``Basic`` authentication details
�basicc C s || _ || _d S )N)�realm�authfunc)�selfr r � r �A/opt/alt/python37/lib/python3.7/site-packages/paste/auth/basic.py�__init__ s zAuthBasicAuthenticator.__init__c C s t �d| j �}t|d�S )NzBasic realm="%s")�headers)ZWWW_AUTHENTICATEZtuplesr r )r �headr r r
�build_authentication$ s z+AuthBasicAuthenticator.build_authenticationc C sp t |�}|s| �� S |�dd�\}}d|�� kr8| �� S |�� �d�}|�dd�\}}| �|||�rh|S | �� S )N� � r �base64�:)Z
AUTHORIZATIONr �split�lower�strip�decoder )r �environZ
authorizationZauthmethZauth�username�passwordr r r
�authenticate( s z#AuthBasicAuthenticator.authenticateN) �__name__�
__module__�__qualname__�__doc__�typer r r �__call__r r r r
r s
r c @ s e Zd ZdZdd� Zdd� ZdS )�AuthBasicHandlera/
HTTP/1.0 ``Basic`` authentication middleware
Parameters:
``application``
The application object is called only upon successful
authentication, and can assume ``environ['REMOTE_USER']``
is set. If the ``REMOTE_USER`` is already set, this
middleware is simply pass-through.
``realm``
This is a identifier for the authority that is requesting
authorization. It is shown to the user and should be unique
within the domain it is being used.
``authfunc``
This is a mandatory user-defined function which takes a
``environ``, ``username`` and ``password`` for its first
three arguments. It should return ``True`` if the user is
authenticated.
c C s || _ t||�| _d S )N)�applicationr r )r r"