� K�gs.��X�ddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZddlmZmZmZejrdd lmZgd �ZGd �d ��ZGd �de��ZGd�de��ZGd�de��ZGd�de��ZGd�dej��ZdS)�)� annotationsN)� b64encode)�parse_http_list�)� ProtocolError)�Cookies�Request�Response)�to_bytes�to_str�unquote)�_Hash)�Auth� BasicAuth� DigestAuth� NetRCAuthc�2�eZdZdZdZdZd d�Zd d�Zd d �Zd S)ra� Base class for all authentication schemes. To implement a custom authentication scheme, subclass `Auth` and override the `.auth_flow()` method. If the authentication scheme does I/O such as disk access or network calls, or uses synchronization primitives such as locks, you should override `.sync_auth_flow()` and/or `.async_auth_flow()` instead of `.auth_flow()` to provide specialized implementations that will be used by `Client` and `AsyncClient` respectively. F�requestr �return�)typing.Generator[Request, Response, None]c#�K�|V�dS)a Execute the authentication flow. To dispatch a request, `yield` it: ``` yield request ``` The client will `.send()` the response back into the flow generator. You can access it like so: ``` response = yield request ``` A `return` (or reaching the end of the generator) will result in the client returning the last response obtained from the server. You can dispatch as many requests as is necessary. N���selfrs �[/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/httpx/_auth.py� auth_flowzAuth.auth_flow&s����,� � � � � �c#�K�|jr|���|�|��}t|��} |V�}|jr|��� |�|��}n#t $rYdSwxYw�H)z� Execute the authentication flow synchronously. By default, this defers to `.auth_flow()`. You should override this method when the authentication scheme does I/O and/or uses concurrency primitives. TN)�requires_request_body�readr�next�requires_response_body�send� StopIteration�rr�flow�responses r�sync_auth_flowzAuth.sync_auth_flow>s����� � %� � �L�L�N�N�N��~�~�g�&�&���t�*�*�� �$�}�}�H��*� �� � ���� ��)�)�H�-�-���� � � � ���� ���� s�#A9�9 B�B�(typing.AsyncGenerator[Request, Response]c�0K�|jr|����d{V��|�|��}t|��} |WV�}|jr|����d{V�� |�|��}n#t $rYdSwxYw�O)z� Execute the authentication flow asynchronously. By default, this defers to `.auth_flow()`. You should override this method when the authentication scheme does I/O and/or uses concurrency primitives. N)r�areadrr!r"r#r$r%s r�async_auth_flowzAuth.async_auth_flowWs����� � %� "��-�-�/�/� !� !� !� !� !� !� !��~�~�g�&�&���t�*�*�� �$�}�}�}�H��*� '��n�n�&�&�&�&�&�&�&�&�&� ��)�)�H�-�-���� � � � ���� ���� s�0B� B�BN�rr rr)rr rr)) �__name__� __module__� __qualname__�__doc__rr"rr(r,rrrrrsh������ � �"��"������0����2�����rrc�"�eZdZdZd d�Zd d �Zd S)� FunctionAuthz� Allows the 'auth' argument to be passed as a simple callable function, that takes the request, and returns a new, modified request. �func�#typing.Callable[[Request], Request]r�Nonec��||_dS�N��_func)rr4s r�__init__zFunctionAuth.__init__ws ���� � � rrr rc#�8K�|�|��V�dSr8r9rs rrzFunctionAuth.auth_flowzs$�����j�j��!�!�!�!�!�!�!rN)r4r5rr6r-)r.r/r0r1r;rrrrr3r3qsF�������� ����"�"�"�"�"�"rr3c�*�eZdZdZdd�Zdd �Zdd �ZdS)rzy Allows the 'auth' argument to be passed as a (username, password) pair, and uses HTTP Basic authentication. �username� str | bytes�passwordrr6c�<�|�||��|_dSr8)�_build_auth_header� _auth_header�rr>r@s rr;zBasicAuth.__init__�s �� �3�3�H�h�G�G����rrr rc#�0K�|j|jd<|V�dS)N� Authorization)rC�headersrs rrzBasicAuth.auth_flow�s"����+/�+<����(�� � � � � r�strc��d�t|��t|��f��}t|�����}d|��S�N�:zBasic ��joinr r�decode�rr>r@�userpass�tokens rrBzBasicAuth._build_auth_header��O���9�9�h�x�0�0�(�8�2D�2D�E�F�F���(�#�#�*�*�,�,������rN�r>r?r@r?rr6r-�r>r?r@r?rrH�r.r/r0r1r;rrBrrrrr~s^�������� H�H�H�H����� � � � � � rrc�,�eZdZdZddd�Zdd �Zdd�ZdS)rzT Use a 'netrc' file to lookup basic auth credentials based on the url host. N�file� str | Nonerr6c�B�ddl}|�|��|_dS)Nr)�netrc� _netrc_info)rrWrZs rr;zNetRCAuth.__init__�s'�� � � � � �;�;�t�,�,����rrr rc#��K�|j�|jj��}|�|ds|V�dS|�|d|d���|jd<|V�dS)N�r)r>r@rF)r[�authenticators�url�hostrBrG)rr� auth_infos rrzNetRCAuth.auth_flow�s}�����$�3�3�G�K�4D�E�E� � � �I�a�L� ��M�M�M�M�M�04�/F�/F�"�1�� �!� �0G�0�0�G�O�O� ,��M�M�M�M�Mrr>r?r@rHc��d�t|��t|��f��}t|�����}d|��SrJrLrOs rrBzNetRCAuth._build_auth_header�rRrr8)rWrXrr6r-rTrUrrrrr�s_��������-�-�-�-�-� � � � � � � � � � rrc ��eZdZUejejejejejejejejd�Zde d<d"d �Z d#d �Z d$d�Z d%d�Z d&d�Zd'd�Zd(d �Zd!S))r)�MD5zMD5-SESS�SHAzSHA-SESSzSHA-256z SHA-256-SESSzSHA-512z SHA-512-SESSz*dict[str, typing.Callable[[bytes], _Hash]]�_ALGORITHM_TO_HASH_FUNCTIONr>r?r@rr6c�r�t|��|_t|��|_d|_d|_dS)Nr)r � _username� _password�_last_challenge� _nonce_countrDs rr;zDigestAuth.__init__�s6��!�(�+�+���!�(�+�+���<@�������rrr rc#�K�|jr#|�||j��|jd<|V�}|jdks d|jvrdS|j�d��D]+}|����d��rn�,dS|�|||��|_d|_|�||j��|jd<|j r(t|j ��� |���|V�dS)NrFi�zwww-authenticatezdigest r�r) rjrBrG� status_code�get_list�lower� startswith�_parse_challengerk�cookiesr�set_cookie_header)rrr'� auth_headers rrzDigestAuth.auth_flow�s:���� � � �/3�/F�/F���-�0�0�G�O�O� ,�!�=�=�� � �3� &� &�*<�H�DT�*T�*T� �F�#�+�4�4�5G�H�H� � �K�� � �"�"�-�-�i�8�8� ��� � �F�#�4�4�W�h� �T�T������+/�+B�+B� �T�)�, �, ����(� � � I� �H�$� %� %� 7� 7�� 7� H� H� H�� � � � � rr'r rurH�_DigestAuthChallengec��|�d��\}}}|���dksJ�i}t|��D]?}|����dd��\} } t | ��|| <�@ |d���} |d���} |�dd��} d |vr|d ���nd }d |vr|d ���nd }t| | | ||� ��S#t$r}d }t||���|�d }~wwxYw)z� Returns a challenge from a Digest WWW-Authenticate header. These take the form of: `Digest realm="realm@host.com",qop="auth,auth-int",nonce="abc",opaque="xyz"` � �digest�=r�realm�nonce� algorithmrd�opaqueN�qop)r{r|r}r~rz(Malformed Digest WWW-Authenticate headerrm) � partitionrpr�strip�splitr �encode�getrv�KeyErrorr)rrr'ru�scheme�_�fields� header_dict�field�key�valuer{r|r}r~r�exc�messages rrrzDigestAuth._parse_challenge�s{��(�1�1�#�6�6����6��|�|�~�~��)�)�)�)�&(� �$�V�,�,� .� .�E������,�,�S�!�4�4�J�C��&�u�~�~�K�� � � C���(�/�/�1�1�E���(�/�/�1�1�E�#��� �U�;�;�I�7?�;�7N�7N�[��*�1�1�3�3�3�TX�F�16�+�1E�1E�+�e�$�+�+�-�-�-�4�C�'��5�I�f�RU���� ��� C� C� C�@�G����9�9�9�s� B����� C���s�BD$�$ E�.E�E� challengec ����|j|j����d�fd� }d�|j|j|jf��}|jj}d�|j � ��|f��}||��}d|j z}|� |j |j ��} |xj dz c_ ||��} |j����d��r&|d�| |j | f����} |�|j|� ��} | � | |j |g} n | |j || | |g} |j|j|j ||d�| ����|j� ��d �} |jr |j| d <| rd | d <|| d<| | d<d|�| ��zS)N�data�bytesrc�b���|��������Sr8)� hexdigestr�)r�� hash_funcs �rryz-DigestAuth._build_auth_header.<locals>.digests)����9�T�?�?�,�,�.�.�5�5�7�7� 7rrKs%08xrz-sessrm)r>r{r|�urir'r}r~�authr�nc�cnoncezDigest )r�r�rr�)rfr}�upperrMrhr{rir_�raw_path�methodr�rk�_get_client_noncer|rp�endswith� _resolve_qoprr~�_get_header_value)rrr�ry�A1�path�A2�HA2�nc_valuer��HA1r� digest_data� format_argsr�s @rrBzDigestAuth._build_auth_header�s����4�Y�5H�5N�5N�5P�5P�Q� � 8� 8� 8� 8� 8� 8��Y�Y��� ����H� I� I���{�#�� �Y�Y���-�-�/�/��6� 7� 7���f�R�j�j���T�.�.���'�'��(9�9�?�K�K�� ���Q�����f�R�j�j�� � � $� $� &� &� /� /�� 8� 8� D��&����C���&�#A�B�B�C�C�C���� � �w��?�?�� �;�� ���5�K�K�� ���6�3��L�K����_��_����t�y�y��5�5�6�6�"�,�3�3�5�5�  � � � � � 5�$-�$4�K�� !� � +�!(�K�� � (�K�� �$*�K�� !��4�1�1�+�>�>�>�>r� nonce_count�intr|r�c�L�t|�����}||z }|tj�����z }|t jd��z }t j|�����dd����S)N��) rHr��time�ctime�os�urandom�hashlib�sha1r�)rr�r|�ss rr�zDigestAuth._get_client_nonce/s��� � � � � #� #� %� %�� �U� �� �T�Z�\�\� � � "� "�"�� �R�Z��]�]����|�A���(�(�*�*�3�B�3�/�6�6�8�8�8r� header_fields�dict[str, bytes]c���d}d}d}d}t|�����D]A\}\}}|dkr|dz }||vr|n|} || �|t|����z }�B|S)N)r}rr�z{}="{}"z{}={}�rz, )� enumerate�items�formatr ) rr��NON_QUOTED_FIELDS�QUOTED_TEMPLATE�NON_QUOTED_TEMPLATE� header_value�ir�r��templates rr�zDigestAuth._get_header_value7s���6��#��%��� �!*�=�+>�+>�+@�+@�!A�!A� B� B� �A�~��u��1�u�u���$� �� 1�1�1� ��(� � �H�O�O�E�6�%�=�=�A�A� A�L�L��rr� bytes | Nonec��|�dStjd|��}d|vrdS|dgkrtd���d|�d�}t||����)Ns, ?r�sauth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authrm)�rer��NotImplementedErrorr)rrr�qopsr�s rr�zDigestAuth._resolve_qopIsj�� �;��4��x���$�$�� �d�?�?��7� �K�=� � �%�&V�W�W� W�B�3�B�B�B���G�W�5�5�5�5rNrSr-)rr r'r rurHrrv)rr r�rvrrH)r�r�r|r�rr�)r�r�rrH)rr�rr rr�)r.r/r0r��md5r��sha256�sha512rf�__annotations__r;rrrrBr�r�r�rrrrr�s���������{��K��|��L��>����>��� O� O�� � � � ����� ����>C�C�C�C�>.?�.?�.?�.?�`9�9�9�9�����$ 6� 6� 6� 6� 6� 6rrc�B�eZdZUded<ded<ded<ded<ded<d S) rvr�r{r|rHr}r�r~rN)r.r/r0r�rrrrvrvWsE��������L�L�L��L�L�L��N�N�N����������rrv)� __future__rr�r�r�r��typing�base64r�urllib.requestr� _exceptionsr�_modelsrr r �_utilsr r r � TYPE_CHECKINGr�__all__rr3rrr� NamedTuplervrrr�<module>r�s���"�"�"�"�"�"����� � � � � � � � � � � � � � � � �������*�*�*�*�*�*�&�&�&�&�&�&�/�/�/�/�/�/�/�/�/�/�-�-�-�-�-�-�-�-�-�-� ��������� ;� :� :��X�X�X�X�X�X�X�X�v "� "� "� "� "�4� "� "� "� � � � � �� � � �& � � � � �� � � �<e6�e6�e6�e6�e6��e6�e6�e6�P�����6�,�����r
Memory