� L�gw���dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZmZmZdd lmZmZmZmZdd lmZmZmZmZdd lmZmZdd l m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3ej4dkrej5Z6nejZ6efd�Z7efd�Z8Gd�d��Z9Gd�de9��Z:d�Z;dS)z� requests.sessions ~~~~~~~~~~~~~~~~~ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). �N)� OrderedDict)� timedelta�)�to_native_string)� HTTPAdapter)�_basic_auth_str)�Mapping� cookielib�urljoin�urlparse)�RequestsCookieJar�cookiejar_from_dict�extract_cookies_to_jar� merge_cookies)�ChunkedEncodingError�ContentDecodingError� InvalidSchema�TooManyRedirects)� default_hooks� dispatch_hook)�DEFAULT_REDIRECT_LIMIT�REDIRECT_STATI�PreparedRequest�Request)�codes)�CaseInsensitiveDict) � DEFAULT_PORTS�default_headers�get_auth_from_url�get_environ_proxies�get_netrc_auth� requote_uri�resolve_proxies� rewind_body�should_bypass_proxies�to_key_val_list�win32c�.�|�|S|�|St|t��rt|t��s|S|t|����}|�t|����d�|���D��}|D]}||=�|S)z�Determines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class` Nc��g|] \}}|�|�� S�N�)�.0�k�vs �a/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/requests/sessions.py� <listcomp>z!merge_setting.<locals>.<listcomp>Ts��E�E�E�v��1�1�9��9�9�9�)� isinstancer r&�update�items)�request_setting�session_setting� dict_class�merged_setting� none_keys�keys r/� merge_settingr;=s��� �������� �?�G�,�,��1;�O�W�1U�1U�����Z��� @� @�A�A�N����/�/�:�:�;�;�;�F�E��!5�!5�!7�!7�E�E�E�I�� � �� �3� � � �r1c��|�|�d��gkr|S|�|�d��gkr|St|||��S)z�Properly merges both requests and session hooks. This is necessary because when request_hooks == {'response': []}, the merge breaks Session hooks entirely. N�response)�getr;)� request_hooks� session_hooksr7s r/� merge_hooksrA[s^�� �� � 1� 1�*� =� =�� C� C����� � 1� 1�*� =� =�� C� C��� �� �z� B� B�Br1c�@�eZdZd�Zd�Z d d�Zd�Zd�Zd �ZdS) �SessionRedirectMixinc�x�|jr2|jd}|�d��}t|d��SdS)z7Receives a Response. Returns a redirect URI or ``None``�location�latin1�utf8N)� is_redirect�headers�encoder)�self�resprEs r/�get_redirect_targetz(SessionRedirectMixin.get_redirect_targetksC�� � � 6��|�J�/�H� ���x�0�0�H�#�H�f�5�5� 5��tr1c�b�t|��}t|��}|j|jkrdS|jdkr|jdvr|jdkr |jdvrdS|j|jk}|j|jk}t j|jd��df}|s|j|vr |j|vrdS|p|S)zFDecide whether Authorization header should be removed when redirectingT�http)�PN�https)i�NFN)r �hostname�scheme�portrr>)rK�old_url�new_url� old_parsed� new_parsed� changed_port�changed_scheme� default_ports r/�should_strip_authz&SessionRedirectMixin.should_strip_auths����g�&�&� ��g�&�&� � � �*�"5� 5� 5��4� � �� '� '���:�-�-��!�W�,�,���;�.�.��5�"��*�/�9� �#�*�j�.?�?��%�)�*�*;�T�B�B�D�I� �� ���<�/�/���<�/�/��5��-�~�-r1FNTc +�K�g} |�|��} t|j��j} | �r'|���} | �|��| dd�|_ |jn8#tttf$r|j � d���YnwxYwt|j��|jkrtd|j�d�|����|���| �d��r=t|j��}d �t'|j��| g��} t| ��}|jd kr| r|�| � ��}n|jr|j} |���} |js#t1|jt3| ����} nt3| ��} t'| ��| _|�| |��|jt8jt8jfvr)d }|D]}| j� |d���d| _!| j}|� d d��tE| j#||j ��tI| j#|j%��| �&| j#��|�'| |��}|�(| |��| j)duod|vpd|v}|rtU| ��| }|r|V�nI|j+|f|||||dd�| ��}tE|j%| |j ��|�|��} |V�| ��%dSdS)zBReceives a Response. Returns a generator of Responses or Requests.rNF)�decode_contentz Exceeded z redirects.)r=z//�:�)�fragment)�Content-Lengthz Content-Type�Transfer-Encoding�Cookierbrc)�stream�timeout�verify�cert�proxies�allow_redirects),rMr �urlra�copy�append�history�contentrr� RuntimeError�raw�read�len� max_redirectsr�close� startswith�joinrrS�_replace�geturl�netlocr r"�rebuild_method� status_coder�temporary_redirect�permanent_redirectrI�pop�bodyr�_cookiesr�cookies�prepare_cookies�rebuild_proxies� rebuild_auth�_body_positionr$�send)rKrL�reqrerfrgrhri�yield_requests�adapter_kwargs�histrk�previous_fragment�prepared_request� parsed_rurl�parsed�purged_headers�headerrI� rewindables r/�resolve_redirectsz&SessionRedirectMixin.resolve_redirects�s��������&�&�t�,�,��$�S�W�-�-�6���g �"�x�x�z�z� � �K�K�� � � �����8�D�L� 4�� � � ��(�*>� �M� 4� 4� 4��� � �U� �3�3�3�3�3� 4�����4�<� � �D�$6�6�6�&�?�� 2�?�?�?�$����� �J�J�L�L�L��~�~�d�#�#� L�&�t�x�0�0� ��h�h� 0��1C� D� D�c�J�K�K���c�]�]�F���"�$�$�):�$����2C��D�D����� 4�$*�O�!��-�-�/�/�C� �=� '��d�h� �C�(8�(8�9�9���!�#�&�&��#3�C�#8�#8� � � � � � 0�$� 7� 7� 7����(��(�(��� "Y��,�?�?�F�$�,�0�0���>�>�>�>�(,� �%�&�.�G� �K�K��$� '� '� '� #�#3�#<�c�4�8� L� L� L� �*�3�T�\� B� B� B� � ,� ,�-=�-F� G� G� G��*�*�+;�W�E�E�G� � � �.�� 5� 5� 5� *�8��D�� �G�+�M�/B�g�/M� � � .��,�-�-�-�#�C�� �� � � � � �t�y�� �!�#�!��#�$)� � �%� � ��'�t�|�5E�t�x�P�P�P��.�.�t�4�4��� � � �O�g �g �g �g �g s�/A7�72B,�+B,c���|j}|j}d|vr#|�|jj|��r|d=|jrt |��nd}|�|�|��dSdS)z�When being redirected we may want to strip authentication from the request to avoid leaking credentials. This method intelligently removes and reapplies authentication where possible to avoid credential loss. � AuthorizationN)rIrkr\�request� trust_envr!� prepare_auth)rKr�r=rIrk�new_auths r/r�z!SessionRedirectMixin.rebuild_auths��� #�*���"�� �g� %� %�$�*@�*@� � � �#�+ �+ � %� ��(�+/�.�B�>�#�&�&�&�d�� � � � )� )�(� 3� 3� 3� 3� 3� � r1c�6�|j}t|j��j}t |||j��}d|vr|d= t ||��\}}n#t$rd\}}YnwxYw|�d��s|r|rt||��|d<|S)a�This method re-evaluates the proxy configuration by considering the environment variables. If we are redirected to a URL covered by NO_PROXY, we strip the proxy configuration. Otherwise, we set missing proxy keys for this URL (in case they were stripped by a previous redirect). This method also replaces the Proxy-Authorization header where necessary. :rtype: dict zProxy-Authorization�NNrQ) rIr rkrSr#r�r�KeyErrorrvr)rKr�rirIrS� new_proxies�username�passwords r/r�z$SessionRedirectMixin.rebuild_proxies.s���#�*���*�.�/�/�6��%�&6����P�P� � �G� +� +��-�.� ,�!2�;�v�3F�!G�!G� �H�h�h��� ,� ,� ,�!+� �H�h�h�h� ,���� � � ��)�)� Q�h� Q�8� Q�-<�X�x�-P�-P�G�)� *��s�A�A*�)A*c���|j}|jtjkr|dkrd}|jtjkr|dkrd}|jtjkr|dkrd}||_dS)z�When being redirected we may want to change the method of the request based on certain specs or browser behavior. �HEAD�GET�POSTN)�methodr|r� see_other�found�moved)rKr�r=r�s r/r{z#SessionRedirectMixin.rebuild_methodMs~��"�(�� � �5�?� 2� 2�v��7G�7G��F� � �5�;� .� .�6�V�3C�3C��F� � �5�;� .� .�6�V�3C�3C��F�"(����r1)FNTNNF) �__name__� __module__� __qualname__rMr\r�r�r�r{r+r1r/rCrCjs����������(.�.�.�H��� ���y�y�y�y�v4�4�4�(���>)�)�)�)�)r1rCc��eZdZdZgd�Zd�Zd�Zd�Zd�Z dd �Z d �Z d �Z d �Z dd �Z dd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�Sessiona�A Requests session. Provides cookie persistence, connection-pooling, and configuration. Basic Usage:: >>> import requests >>> s = requests.Session() >>> s.get('https://httpbin.org/get') <Response [200]> Or as a context manager:: >>> with requests.Session() as s: ... s.get('https://httpbin.org/get') <Response [200]> ) rIr��authri�hooks�paramsrgrh�adaptersrer�rtc��t��|_d|_i|_t ��|_i|_d|_d|_d|_ t|_ d|_ ti��|_t��|_|�dt%����|�dt%����dS)NFTzhttps://zhttp://)rrIr�rirr�r�rergrhrrtr�rr�rr��mountr�rKs r/�__init__zSession.__init__�s���'�(�(�� ��� � �� �#�_�_�� � �� ��� ��� ��� � 4������ +�2�.�.�� �$� � �� � � � �:�{�}�}�-�-�-� � � �9�k�m�m�,�,�,�,�,r1c��|Sr*r+r�s r/� __enter__zSession.__enter__�s��� r1c�.�|���dSr*)ru)rK�argss r/�__exit__zSession.__exit__�s�� � � � � � � � r1c��|jpi}t|tj��st |��}t t t ��|j��|��}|j}|jr|s|jst|j ��}t��}|� |j ���|j |j|j|jt%|j|jt(���t%|j|j��t%||j��|t-|j|j���� � |S)a�Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. The :class:`PreparedRequest` has settings merged from the :class:`Request <Request>` instance and those of the :class:`Session`. :param request: :class:`Request` instance to prepare with this session's settings. :rtype: requests.PreparedRequest )r7) r�rk�files�data�jsonrIr�r�r�r�)r�r2r � CookieJarrrr r�r�r!rkr�preparer��upperr�r�r�r;rIrr�rAr�)rKr�r��merged_cookiesr��ps r/�prepare_requestzSession.prepare_request�s5���/�'�R���'�9�#6�7�7� 3�)�'�2�2�G�'� �+�-�-�t�|� <� <�g� � �� �|�� �>� /�$� /�t�y� /�!�'�+�.�.�D� � � �� � � ��>�'�'�)�)�� ��-�����!�����:M����!�����=�=��t�T�Y�/�/�"��g�m�T�Z�8�8� � � � ��r1NTc �"�t|���||||pi||pi||| �� � }|�|��}| pi} |�|j| | ||��}| | d�}|�|��|j|fi|��}|S)a� Constructs a :class:`Request <Request>`, prepares it and sends it. Returns :class:`Response <Response>` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. :param files: (optional) Dictionary of ``'filename': file-like-objects`` for multipart encoding upload. :param auth: (optional) Auth tuple or callable to enable Basic/Digest/Custom HTTP Auth. :param timeout: (optional) How long to wait for the server to send data before giving up, as a float, or a :ref:`(connect timeout, read timeout) <timeouts>` tuple. :type timeout: float or tuple :param allow_redirects: (optional) Set to True by default. :type allow_redirects: bool :param proxies: (optional) Dictionary mapping protocol or protocol and hostname to the URL of the proxy. :param hooks: (optional) Dictionary mapping hook name to one event or list of events, event must be callable. :param stream: (optional) whether to immediately download the response content. Defaults to ``False``. :param verify: (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to ``True``. When set to ``False``, requests will accept any TLS certificate presented by the server, and will ignore hostname mismatches and/or expired certificates, which will make your application vulnerable to man-in-the-middle (MitM) attacks. Setting verify to ``False`` may be useful during local development or testing. :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. :rtype: requests.Response ) r�rkrIr�r�r�r�r�r�r�)rfrj)rr�r��merge_environment_settingsrkr3r�)rKr�rkr�r�rIr�r�r�rfrjrir�rergrhr�r��prep�settings� send_kwargsrLs r/r�zSession.request�s���~��<�<�>�>���������<�R����  �  �  ���#�#�C�(�(���-�R���2�2� �H�g�v�v�t� � �� �.� � � � ���8�$�$�$��t�y��-�-��-�-��� r1c �L�|�dd��|jd|fi|��S)z�Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response rjTr��� setdefaultr��rKrk�kwargss r/r>z Session.getQs7�� ���+�T�2�2�2��t�|�E�3�1�1�&�1�1�1r1c �L�|�dd��|jd|fi|��S)z�Sends a OPTIONS request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response rjT�OPTIONSr�r�s r/�optionszSession.options\s7�� ���+�T�2�2�2��t�|�I�s�5�5�f�5�5�5r1c �L�|�dd��|jd|fi|��S)z�Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response rjFr�r�r�s r/�headz Session.headgs7�� ���+�U�3�3�3��t�|�F�C�2�2�6�2�2�2r1c �&�|jd|f||d�|��S)a�Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param json: (optional) json to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response r�)r�r��r�)rKrkr�r�r�s r/�postz Session.postrs'���t�|�F�C�H�d��H�H��H�H�Hr1c �$�|jd|fd|i|��S)auSends a PUT request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response �PUTr�r��rKrkr�r�s r/�putz Session.puts%���t�|�E�3�<�<�T�<�V�<�<�<r1c �$�|jd|fd|i|��S)awSends a PATCH request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param data: (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the :class:`Request`. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response �PATCHr�r�r�s r/�patchz Session.patch�s%���t�|�G�S�>�>�t�>�v�>�>�>r1c � �|jd|fi|��S)z�Sends a DELETE request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. :param \*\*kwargs: Optional arguments that ``request`` takes. :rtype: requests.Response �DELETEr�r�s r/�deletezSession.delete�s ���t�|�H�c�4�4�V�4�4�4r1c �.�|�d|j��|�d|j��|�d|j��d|vrt ||j|j��|d<t|t��rtd���|� dd��}|� d��}|j }|� |j���}t��}|j|fi|��}t��|z } t#| � ��|_t'd ||fi|��}|jr*|jD]"} t+|j| j| j���#t+|j||j��|r|j||fi|��} d �| D��} ng} | r1| �d |��| � ��}| |_|s5 t7|j||fd di|����|_n#t:$rYnwxYw|s|j|S)zISend a given PreparedRequest. :rtype: requests.Response rergrhriz#You can only send PreparedRequests.rjT)rk)�secondsr=c��g|]}|��Sr+r+)r,rLs r/r0z Session.send.<locals>.<listcomp>�s��,�,�,��t�,�,�,r1rr�)r�rergrhr#rir�r2r� ValueErrorrr>r�� get_adapterrk�preferred_clockr�r�elapsedrrnrr�r�rqr��insert�next�_next� StopIterationro) rKr�r�rjrer��adapter�start�rr�rL�genrns r/r�z Session.send�s��� ���(�D�K�0�0�0����(�D�K�0�0�0����&�$�)�,�,�,� �F� "� "� /����t�~� V� V�F�9� � �g�w� '� '� D��B�C�C� C�!�*�*�%6��=�=�����H�%�%��� ���"�"�w�{�"�3�3�� �!�!�� �G�L�� +� +�F� +� +��"�#�#�e�+���g�.�.�.�� � �*�e�Q� 9� 9�&� 9� 9�� �9� M�� � M� M��&�t�|�T�\�4�8�L�L�L�L��t�|�W�a�e�<�<�<� � �(�$�(��G�>�>�v�>�>�C�,�,��,�,�,�G�G��G� � � �N�N�1�a� � � �� � � � �A��A�I�� � ��*�D�*�1�g�U�U�d�U�f�U�U�������!� � � ��� ����� � �I�I��s�#G<�< H �H c��|jr�|�|�d��nd}t||���}|���D]\}} |�|| ���|dus|�@t j�d��p t j�d��p|}t||j��}t||j ��}t||j ��}t||j ��}||||d�S)z^ Check the environment and merge it with some settings. :rtype: dict N�no_proxy)r�T�REQUESTS_CA_BUNDLE�CURL_CA_BUNDLE)rirergrh) r�r>r r4r��os�environr;rirergrh) rKrkrirergrhr�� env_proxiesr-r.s r/r�z"Session.merge_environment_settings�s�� �>� �29�2E�w�{�{�:�.�.�.�4�H�-�c�H�E�E�E�K�#�)�)�+�+� )� )���1��"�"�1�a�(�(�(�(���~�~����J�N�N�#7�8�8���z�~�~�&6�7�7���� ����6�6���v�t�{�3�3���v�t�{�3�3���T�4�9�-�-��"�f��PT�U�U�Ur1c���|j���D]B\}}|����|�����r|cS�Ct d|�����)z~ Returns the appropriate connection adapter for the given URL. :rtype: requests.adapters.BaseAdapter z&No connection adapters were found for )r�r4�lowerrvr)rKrk�prefixr�s r/r�zSession.get_adapter sr�� $�}�2�2�4�4� � �O�F�G��y�y�{�{�%�%�f�l�l�n�n�5�5� ����� ��L�S�L�L�M�M�Mr1c�f�|j���D]}|����dS)z+Closes all adapters and as such the sessionN)r��valuesru)rKr.s r/ruz Session.closes8����%�%�'�'� � �A� �G�G�I�I�I�I� � r1c���||j�<�fd�|jD��}|D]$}|j�|��|j|<�%dS)zwRegisters a connection adapter to a prefix. Adapters are sorted in descending order by prefix length. c�T��g|]$}t|��t���k�"|��%Sr+)rs)r,r-r�s �r/r0z!Session.mount.<locals>.<listcomp>%s/���I�I�I�a�C��F�F�S��[�[�4H�4H��4H�4H�4Hr1N)r�r)rKr�r�� keys_to_mover:s ` r/r�z Session.mountsd��� !(�� �f��I�I�I�I�4�=�I�I�I� �� 8� 8�C�!%��!2�!2�3�!7�!7�D�M�#� � � 8� 8r1c�.���fd��jD��}|S)Nc�4��i|]}|t�|d����Sr*)�getattr)r,�attrrKs �r/� <dictcomp>z(Session.__getstate__.<locals>.<dictcomp>+s'���L�L�L�T��w�t�T�4�0�0�L�L�Lr1)� __attrs__)rK�states` r/� __getstate__zSession.__getstate__*s#���L�L�L�L�T�^�L�L�L��� r1c�\�|���D]\}}t|||���dSr*)r4�setattr)rKrr�values r/� __setstate__zSession.__setstate__.s<�� �;�;�=�=� '� '�K�D�%� �D�$�� &� &� &� &� '� 'r1)NNNNNNNTNNNNNNr�r*)r�r�r��__doc__rr�r�r�r�r�r>r�r�r�r�r�r�r�r�r�rur�rr r+r1r/r�r�ds���������$ � � �I�;-�;-�;-�z������)�)�)�^� ���� ������� � �#[�[�[�[�z 2� 2� 2� 6� 6� 6� 3� 3� 3� I� I� I� I� =� =� =� =� ?� ?� ?� ?�5�5�5�K�K�K�ZV�V�V�> N� N� N���� 8� 8� 8����'�'�'�'�'r1r�c��t��S)aZ Returns a :class:`Session` for context-management. .. deprecated:: 1.0.0 This method has been deprecated since version 1.0.0 and is only kept for backwards compatibility. New code should use :class:`~requests.sessions.Session` to create a session. This may be removed at a future date. :rtype: Session )r�r+r1r/�sessionr 3s�� �9�9�r1)<r r��sys�time� collectionsr�datetimer�_internal_utilsrr�rr�r�compatr r r r r�r rrr� exceptionsrrrrr�rr�modelsrrrr� status_codesr� structuresr�utilsrrrr r!r"r#r$r%r&�platform� perf_counterr�r;rArCr�r r+r1r/�<module>rs����� � � � � � � � � � � � �#�#�#�#�#�#�������-�-�-�-�-�-�!�!�!�!�!�!�!�!�!�!�!�!�9�9�9�9�9�9�9�9�9�9�9�9������������� ������������ 0�/�/�/�/�/�/�/�������������  ������+�+�+�+�+�+� � � � � � � � � � � � � � � � � � � � � � � � ��<�7����'�O�O��i�O�@K�����<:E� C� C� C� C�w)�w)�w)�w)�w)�w)�w)�w)�tL'�L'�L'�L'�L'�"�L'�L'�L'�^ � � � � r1
Memory