3 P\P @ sR d Z ddlmZ ddlmZ ddlmZmZ G dd dejZ G dd d e Z d S )z-The module containing the code for GuessAuth. )auth)cookies )_digest_auth_compathttp_proxy_digestc @ s8 e Zd ZdZdd Zdd Zdd Zdd Zd d ZdS ) GuessAuthz7Guesses the auth type by the WWW-Authentication header.c C s || _ || _d | _d | _d S )N)usernamepasswordr pos)selfr r r /usr/lib/python3.6/guess.py__init__ s zGuessAuth.__init__c C s | j d k r|jjj| j |j |jj |jj }t|dsHt j |_t j|j|j|j |j |j tj| j| j| _| j|}|jj|f|}|jj| ||_|S )N_cookies)r requestbodyseekcontentrawrelease_conncopyhasattrr RequestsCookieJarr extract_cookies_to_jarprepare_cookiesr Z HTTPBasicAuthr r connectionsendhistoryappend)r rkwargsprep_rr r r _handle_basic_auth_401 s z GuessAuth._handle_basic_auth_401c C sf t j| j| j| _y| jj W n tk r4 Y nX t| jdrV| jjd krVd| j_| jj |f|S )N num_401_callsr ) auth_compatZHTTPDigestAuthr r r init_per_thread_stateAttributeErrorr r$ handle_401)r r r r r r _handle_digest_auth_401' s z!GuessAuth._handle_digest_auth_401c K s> |j jddj }d|kr&| j||S d|kr:| j||S dS )z/Resends a request with auth headers, if needed.zwww-authenticate basicdigestN)headersgetlowerr# r) )r r r Zwww_authenticater r r r( : s zGuessAuth.handle_401c C sL | j d k r| j |S y|jj | _W n tk r8 Y nX |jd| j |S )Nresponse)r r tellr r' register_hookr( )r r r r r __call__E s zGuessAuth.__call__N) __name__ __module____qualname____doc__r r# r) r( r3 r r r r r s r c sF e Zd ZdZd fdd Zdd Zdd Zd d Z fddZ Z S )GuessProxyAuthzZ Guesses the auth type by WWW-Authentication and Proxy-Authentication headers Nc s( t t| j|| || _|| _d | _d S )N)superr8 r proxy_usernameproxy_password proxy_auth)r r r r: r; ) __class__r r r W s zGuessProxyAuth.__init__c C s | j d k r|jjj| j |j |jj |jj }t|dsHt j |_t j|j|j|j |j |j tj| j| j| _| j|}|jj|f|}|jj| ||_|S )Nr )r r r r r r r r r r r r r r r Z HTTPProxyAuthr: r; r<