File: //opt/alt/python37/lib/python3.7/site-packages/paste/auth/__pycache__/grantip.cpython-37.pyc
B
a�N� � @ s. d Z ddlmZ G dd� de�Zd dd�ZdS )
z-
Grant roles and logins based on IP address.
� )�ip4c @ s2 e Zd ZdZddd�Zdd� Zdd� Zd d
� ZdS )
�GrantIPMiddlewarea
On each request, ``ip_map`` is checked against ``REMOTE_ADDR``
and logins and roles are assigned based on that.
``ip_map`` is a map of {ip_mask: (username, roles)}. Either
``username`` or ``roles`` may be None. Roles may also be prefixed
with ``-``, like ``'-system'`` meaning that role should be
revoked. ``'__remove__'`` for a username will remove the username.
If ``clobber_username`` is true (default) then any user
specification will override the current value of ``REMOTE_USER``.
``'__remove__'`` will always clobber the username.
``ip_mask`` is something that `paste.util.ip4:IP4Range
<class-paste.util.ip4.IP4Range.html>`_ can parse. Simple IP
addresses, IP/mask, ip<->ip ranges, and hostnames are allowed.
Tc C sR || _ g | _x:|�� D ].\}}| j�t�|�| �|d |d �f� qW || _d S )Nr � )�app�ip_map�items�appendr ZIP4Range�_convert_user_role�clobber_username)�selfr r r
�key�value� r �C/opt/alt/python37/lib/python3.7/site-packages/paste/auth/grantip.py�__init__ s zGrantIPMiddleware.__init__c C s |rt |t�r|�d�}||fS )N�,)�
isinstance�
basestring�split)r �username�rolesr r r r $ s
z$GrantIPMiddleware._convert_user_rolec C s� t �|d d�}d}g }xV| jD ]L\}\}}||kr |rB|�|� |dkrPd}q |r |�d�rd| jr ||d<