U
    
W[™  ã                   @   s`   d Z ddlmZmZ ddlZddlmZ ddlmZm	Z	 ddl
mZ eeƒG dd„ deƒƒZdS )	z¡
HTTP BASIC authentication.

@see: U{http://tools.ietf.org/html/rfc1945}
@see: U{http://tools.ietf.org/html/rfc2616}
@see: U{http://tools.ietf.org/html/rfc2617}
é    )ÚdivisionÚabsolute_importN)Úimplementer)ÚcredentialsÚerror)ÚICredentialFactoryc                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
ÚBasicCredentialFactoryzÌ
    Credential Factory for HTTP Basic Authentication

    @type authenticationRealm: L{bytes}
    @ivar authenticationRealm: The HTTP authentication realm which will be issued in
        challenges.
    s   basicc                 C   s
   || _ d S )N©ÚauthenticationRealm)Úselfr
   © r   ú9/usr/lib/python3/dist-packages/twisted/web/_auth/basic.pyÚ__init__#   s    zBasicCredentialFactory.__init__c                 C   s
   d| j iS )zy
        Return a challenge including the HTTP authentication realm with which
        this factory was created.
        Zrealmr	   )r   Úrequestr   r   r   ÚgetChallenge'   s    z#BasicCredentialFactory.getChallengec                 C   sd   zt  |d ¡}W n  t jk
r2   t d¡‚Y nX | dd¡}t|ƒdkrVtj|Ž S t d¡‚dS )zŠ
        Parse the base64-encoded, colon-separated username and password into a
        L{credentials.UsernamePassword} instance.
        s   ===zInvalid credentialsó   :é   é   N)	ÚbinasciiZ
a2b_base64ÚErrorr   ZLoginFailedÚsplitÚlenr   ZUsernamePassword)r   Zresponser   Zcredsr   r   r   Údecode/   s    
zBasicCredentialFactory.decodeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Zschemer   r   r   r   r   r   r   r      s
   r   )r   Z
__future__r   r   r   Zzope.interfacer   Ztwisted.credr   r   Ztwisted.web.iwebr   Úobjectr   r   r   r   r   Ú<module>   s   