OwlCyberSecurity - MANAGER
Edit File: auth.cpython-36.pyc
3 �Pf�&������������������@���s����d�Z�ddlZddlZddlZddlZddlZddlZddlmZ�ddl m Z mZmZ�ddl mZ�ddlmZ�ddlmZ�d Zd Zdd��ZG�d d��de�ZG�dd��de�ZG�dd��de�ZG�dd��de�ZdS�)z] requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. �����N)� b64encode����)�urlparse�str� basestring)�extract_cookies_to_jar)�to_native_string)�parse_dict_headerz!application/x-www-form-urlencodedzmultipart/form-datac�������������C���s����t�|�t�s&tjdj|��td��t|��}�t�|t�sLtjdj|�td��t|�}t�|�t�r`|�jd�}�t�|t�rt|jd�}dtt dj |�|f��j����}|S�)zReturns a Basic Auth string.z�Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.)�categoryz�Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in ({0!r}) to a string or bytes object in the near future to avoid problems.�latin1zBasic ����:)� isinstancer����warnings�warn�format�DeprecationWarningr����encoder���r����join�strip)�username�passwordZauthstr��r����/usr/lib/python3.6/auth.py�_basic_auth_str���s&���� r���c���������������@���s���e�Zd�ZdZdd��ZdS�)�AuthBasez4Base class that all auth implementations derive fromc�������������C���s���t�d��d�S�)NzAuth hooks must be callable.)�NotImplementedError)�self�rr���r���r����__call__K���s����zAuthBase.__call__N)�__name__� __module__�__qualname__�__doc__r���r���r���r���r���r���H���s���r���c���������������@���s0���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd S�)� HTTPBasicAuthz?Attaches HTTP Basic Authentication to the given Request object.c�������������C���s���||�_�||�_d�S�)N)r���r���)r���r���r���r���r���r����__init__R���s����zHTTPBasicAuth.__init__c�������������C���s(���t�|�jt|dd��k|�jt|dd��kg�S�)Nr���r���)�allr����getattrr���)r����otherr���r���r����__eq__V���s����zHTTPBasicAuth.__eq__c�������������C���s ���|�|k�S�)Nr���)r���r'���r���r���r����__ne__\���s����zHTTPBasicAuth.__ne__c�������������C���s���t�|�j|�j�|jd<�|S�)N� Authorization)r���r���r����headers)r���r���r���r���r���r���_���s����zHTTPBasicAuth.__call__N)r���r ���r!���r"���r$���r(���r)���r���r���r���r���r���r#���O���s ���r#���c���������������@���s���e�Zd�ZdZdd��ZdS�)� HTTPProxyAuthz=Attaches HTTP Proxy Authentication to a given Request object.c�������������C���s���t�|�j|�j�|jd<�|S�)NzProxy-Authorization)r���r���r���r+���)r���r���r���r���r���r���g���s����zHTTPProxyAuth.__call__N)r���r ���r!���r"���r���r���r���r���r���r,���d���s���r,���c���������������@���sP���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dd��ZdS�)�HTTPDigestAuthz@Attaches HTTP Digest Authentication to the given Request object.c�������������C���s���||�_�||�_tj��|�_d�S�)N)r���r���� threadingZlocal� _thread_local)r���r���r���r���r���r���r$���o���s����zHTTPDigestAuth.__init__c�������������C���s@���t�|�jd�s<d|�j_d|�j_d|�j_i�|�j_d�|�j_d�|�j_d�S�)N�initT��r���)�hasattrr/���r0���� last_nonce�nonce_count�chal�pos� num_401_calls)r���r���r���r����init_per_thread_stateu���s����z$HTTPDigestAuth.init_per_thread_statec����������������sj��|�j�jd�}|�j�jd�}|�j�jjd�}|�j�jjd�}|�j�jjd�}d��|dkrTd}n|j��}|dksl|dkrzd d ��} | ��n|dkr�dd ��} | ����fdd�}��dkr�dS�d}t|�} | jp�d}| jr�|d| j�7�}d|�j||�jf�}d||f�}��|�}��|�}||�j�j k�r|�j��j d7��_ nd|�j�_ d|�j�j �}t|�j�j �jd�}||jd�7�}|t j��jd�7�}|tjd�7�}tj|�j��dd��}|dk�r���d|||f��}|�s�||d||f��}n<|dk�s�d|jd�k�r�d|||d|f�}|||�}ndS�||�j�_ d|�j||||f�}|�r(|d|�7�}|�r:|d|�7�}|�rL|d|�7�}|�rb|d ||f�7�}d!|�S�)"z :rtype: str �realm�nonce�qop� algorithm�opaqueNZMD5zMD5-SESSc�������������S���s"���t�|�t�r|�jd�}�tj|��j��S�)Nzutf-8)r ���r���r����hashlibZmd5� hexdigest)�xr���r���r����md5_utf8����s���� z4HTTPDigestAuth.build_digest_header.<locals>.md5_utf8ZSHAc�������������S���s"���t�|�t�r|�jd�}�tj|��j��S�)Nzutf-8)r ���r���r���r>����sha1r?���)r@���r���r���r����sha_utf8����s���� z4HTTPDigestAuth.build_digest_header.<locals>.sha_utf8c����������������s�����d|�|f��S�)Nz%s:%sr���)�s�d)� hash_utf8r���r����<lambda>����s����z4HTTPDigestAuth.build_digest_header.<locals>.<lambda>�/�?z%s:%s:%sz%s:%sr���z%08xzutf-8��������Zauth�,z%s:%s:%s:%s:%sz>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z , opaque="%s"z, algorithm="%s"z , digest="%s"z , qop="auth", nc=%s, cnonce="%s"z Digest %s)r/���r5����get�upperr����pathZqueryr���r���r3���r4���r���r����timeZctime�os�urandomr>���rB���r?����split)r����method�urlr9���r:���r;���r<���r=���Z _algorithmrA���rC���ZKDZentdigZp_parsedrO���ZA1ZA2ZHA1ZHA2ZncvaluerD���ZcnonceZrespdigZnoncebit�baser���)rF���r����build_digest_header���sr���� z"HTTPDigestAuth.build_digest_headerc�������������K���s���|j�rd|�j_dS�)z)Reset num_401_calls counter on redirects.r���N)Zis_redirectr/���r7���)r���r����kwargsr���r���r����handle_redirect����s����zHTTPDigestAuth.handle_redirectc�������������K���s"��d|j���kodk�n��s&d|�j_|S�|�jjdk rD|jjj|�jj��|jjdd�}d|j ��koh|�jjdk��r|�j�jd7��_t jd t jd �}t |jd|dd��|�j_|j�|j���|jj��}t|j|j|j��|j|j��|�j|j|j�|jd<�|jj|f|�}|jj|��||_|S�d|�j_|S�) zo Takes the given response and tries digest-auth, if needed. :rtype: requests.Response i���i���r���Nzwww-authenticater1���Zdigest����zdigest )�flags)�countr*���)Zstatus_coder/���r7���r6���Zrequest�body�seekr+���rM����lower�re�compile� IGNORECASEr ����subr5���Zcontent�close�copyr���Z_cookies�rawZprepare_cookiesrW���rT���rU���Z connection�send�history�append)r���r���rX���Zs_authZpatZprepZ_rr���r���r���� handle_401����s.���� zHTTPDigestAuth.handle_401c�������������C���s~���|�j����|�jjr&|�j|j|j�|jd<�y|jj��|�j_ W�n�t k rT���d�|�j_ Y�nX�|jd|�j��|jd|�j ��d|�j_|S�)Nr*���Zresponser���)r8���r/���r3���rW���rT���rU���r+���r]����tellr6����AttributeErrorZ register_hookrj���rY���r7���)r���r���r���r���r���r��� ��s����zHTTPDigestAuth.__call__c�������������C���s(���t�|�jt|dd��k|�jt|dd��kg�S�)Nr���r���)r%���r���r&���r���)r���r'���r���r���r���r(�����s����zHTTPDigestAuth.__eq__c�������������C���s ���|�|k�S�)Nr���)r���r'���r���r���r���r)���$��s����zHTTPDigestAuth.__ne__N)r���r ���r!���r"���r$���r8���rW���rY���rj���r���r(���r)���r���r���r���r���r-���l���s��� Z,r-���)r"���rQ���r`���rP���r>���r.���r����base64r����compatr���r���r���Zcookiesr���Z_internal_utilsr���Zutilsr ���ZCONTENT_TYPE_FORM_URLENCODEDZCONTENT_TYPE_MULTI_PARTr����objectr���r#���r,���r-���r���r���r���r����<module>���s$���,