U
    c6{i^  ã                   @   sN   d 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ƒƒ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}
é    N)Ú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
   ú;/tmp/pip-unpacked-wheel-hfbvu0bz/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.
        Ú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)	ÚbinasciiÚ
a2b_base64ÚErrorr   ZLoginFailedÚsplitÚlenr   ZUsernamePassword)r	   Úresponser   Úcredsr
   r
   r   Údecode,   s    
zBasicCredentialFactory.decodeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úschemer   r   r   r
   r
   r
   r   r      s
   r   )
r   r   Zzope.interfacer   Ztwisted.credr   r   Ztwisted.web.iwebr   r   r
   r
   r
   r   Ú<module>   s   	