� ��^iE7���dZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ej e��Zejd��Zd �ZGd �d e��ZdS) z7 The httplib2 algorithms ported for use with requests. �N)� parsedate_tz)�CaseInsensitiveDict�)� DictCache)� Serializerz9^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?c��t�|�����}|d|d|d|d|dfS)z�Parses a URI using the regex given in Appendix B of RFC 3986. (scheme, authority, path, query, fragment) = parse_uri(uri) r����)�URI�match�groups)�urirs ��/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-4.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/cachecontrol/controller.py� parse_urirsD�� �Y�Y�s�^�^� "� "� $� $�F� �1�I�v�a�y�&��)�V�A�Y��q� � B�B�c�h�eZdZdZ d d�Zed���Zed���Zd�Zd�Z d �Z d d �Z d �Z dS)�CacheControllerz9An interface to see if request should cached or not. NTc�~�|�t��n||_||_|p t��|_|pd|_dS)N)����i,�-)r�cache� cache_etagsr� serializer�cacheable_status_codes)�selfrrr� status_codess r�__init__zCacheController.__init__"sC��%*�M�Y�[�[�[�u�� �&���$�4� � � ���&2�&J�6J��#�#�#rc��t|��\}}}}}|r|std|z���|���}|���}|sd}|rd�||g��p|}|dz|z|z}|S)z4Normalize the URL to create a safe key for the cachez(Only absolute URIs are allowed. uri = %s�/�?z://)r� Exception�lower�join) �clsr�scheme� authority�path�query�fragment� request_uri� defrag_uris r�_urlnormzCacheController._urlnorm*s���6?�s�^�^�2���D�%��� N�Y� N��F��L�M�M� M��������O�O�%�%� �� ��D��7����$��� 7� 7�?�4� ��e�^�i�/�+�=� ��rc�,�|�|��S�N)r/)r'rs r� cache_urlzCacheController.cache_url>s���|�|�C� � � rc ���tdftdftdfddddddddtdfd� }|�d|�dd����}i}|�d��D�] }|���s�|�d d ��}|d ���} ||\}} n+#t$rt �d |��Y�|wxYw|r| sd||<|r� ||d �����||<��#t$r | rt �d |��Y��t$r%t �d||j ��Y�� wxYw��|S)NTF)NF) �max-agez max-stale� min-fresh�no-cache�no-storez no-transformzonly-if-cachedzmust-revalidate�public�privatezproxy-revalidatezs-maxagez cache-controlz Cache-Control��,�=rrz,Ignoring unknown cache-control directive: %sz-Missing value for cache-control directive: %sz8Invalid value for cache-control directive %s, must be %s) �int�get�split�strip�KeyError�logger�debug� IndexError� ValueError�__name__) r�headers�known_directives� cc_headers�retval� cc_directive�parts� directive�typ�requireds r�parse_cache_controlz#CacheController.parse_cache_controlBs����T�{��u���t��%�%�)�+�,�#�$� -��d� � � �� �[�[��'�+�+�o�r�2R�2R�S�S� ���&�,�,�S�1�1� � �L��%�%�'�'� �� �&�&�s�A�.�.�E��a����(�(�I� � 0�� ;� ��X�X��� � � �� � �K�Y�W�W�W��� ����� )�h� )�$(��y�!�� � �(+��E�!�H�N�N�,<�,<�(=�(=�F�9�%�%��!������� � �N�%������"�����L�L�U�!�� ���������� � � s*�6 C�%C*�)C*�9&D � 'E7� *E7�6E7c���|�|j��}t�d|��|�|j��}d|vrt�d��dSd|vr(|ddkrt�d��dS|j�|��}|�t�d ��dS|j� ||��}|st� d ��dS|j d krd }t�|��|St|j��}|rd |vrTd|vr4t�d��|j� |��t�d��dStj��}tjt#|d ����} t%d|| z ��} t�d| ��|�|��} d} d| vr$| d} t�d| ��n]d|vrYt#|d��} | �Btj| ��| z }t%d|��} t�d| ��d|vr#|d} t�d| ��d|vr(|d}| |z } t�d| ��| | kr8t�d��t�d| | ��|Sd|vr4t�d��|j� |��dS)ze Return a cached response if it exists in the cache, otherwise return False. zLooking up "%s" in the cacher6z-Request header has "no-cache", cache bypassedFr4rz1Request header has "max_age" as 0, cache bypassedNzNo cache entry availablez1Cache entry deserialization failed, entry ignoredrzVReturning cached "301 Moved Permanently" response (ignoring date and etag information)�date�etagz(Purging cached response: no date or etagz!Ignoring cached response: no datezCurrent age based on date: %iz#Freshness lifetime from max-age: %i�expiresz#Freshness lifetime from expires: %iz+Freshness lifetime from request max-age: %ir5z'Adjusted current age from min-fresh: %iz2The response is "fresh", returning cached responsez%i > %iz4The cached response is "stale" with no etag, purging)r2�urlrBrCrPrGrr>r�loads�warning�statusr�delete�time�calendar�timegmr�max)r�requestr2�cc� cache_data�resp�msgrG�nowrR� current_age�resp_cc�freshness_lifetimerT� expire_time� min_freshs r�cached_requestzCacheController.cached_requestxs|�� �N�N�7�;�/�/� �� � �3�Y�?�?�?� � %� %�g�o� 6� 6�� �� � � �L�L�H� I� I� I��5� ��?�?�r�)�}��1�1� �L�L�L� M� M� M��5��Z�^�^�I�.�.� � � � �L�L�3� 4� 4� 4��5���$�$�W�j�9�9��� � �N�N�N� O� O� O��5� �;�#� � �7� � �L�L�� � � ��K�%�d�l�3�3��� �&��/�/��W�$�$�� � �G�H�H�H�� �!�!�)�,�,�,� �L�L�<� =� =� =��5��i�k�k����|�G�F�O�<�<�=�=���!�S�4�Z�(�(� �� � �4�k�B�B�B� �*�*�7�3�3���� �� � �!(��!3� � �L�L�>�@R� S� S� S� S��'� !� !�"�7�9�#5�6�6�G��"�&�o�g�6�6��=� �%(��K�%8�%8�"�� � �B�DV�W�W�W� ��?�?�!#�I�� � �L�L�=�?Q� � � � �"� � ��;��I� �9� $�K� �L�L�B�K� P� P� P� � � +� +� �L�L�M� N� N� N� �L�L��$6� � D� D� D��K� �� � � �L�L�O� P� P� P� �J� � �i� (� (� (��urc� �|�|j��}|j�||j�|����}i}|r2t |j��}d|vr |d|d<d|vr |d|d<|S)NrS�ETagz If-None-Matchz last-modifiedz Last-ModifiedzIf-Modified-Since)r2rUrrVrr>rrG)rr^r2ra� new_headersrGs r�conditional_headersz#CacheController.conditional_headers�s����N�N�7�;�/�/� ���$�$�W�d�j�n�n�Y�.G�.G�H�H��� � � L�)�$�,�7�7�G��� � �/6�v�� �O�,��'�)�)�3:�?�3K� �/�0��rc��|p|j}|j|vr#t�d|j|��dSt |j��}|�Fd|vrB|d���r(t|d��t|��krdS|� |j��}|� |��}|� |j ��} t�d| ��d} d|vrd} t�d��d|vrd} t�d ��| rN|j � | ��r4t�d ��|j �| ��| rdSd |� d d ��vrt�d��dS|jrVd|vrRt�d��|j �| |j�|||�����dS|jdkrPt�d��|j �| |j�||����dSd|vr�d|vr^|ddkrRt�d��|j �| |j�|||�����dSd|vr\|drVt�d��|j �| |j�|||�����dSdSdSdS)zc Algorithm for caching requests. This assumes a requests Response object. zStatus code %s not in %sN�content-lengthz&Updating cache with response from "%s"Fr7TzResponse header has "no-store"zRequest header has "no-store"z0Purging existing cache entry to honor "no-store"�*�varyr:zResponse header has "Vary: *"rSzCaching due to etag)�bodyrzCaching permanant redirectrRr4rz'Caching b/c date exists and max-age > 0rTzCaching b/c of expires header)rrXrBrCrrG�isdigitr=�lenrPr2rUrr>rYr�setr�dumps) rr^�responserrrr�response_headers�cc_reqr_r2�no_stores r�cache_responsezCacheController.cache_response�s���".�!L��1L�� �?�"8� 8� 8� �L�L�*�H�O�=S� � � � �F�.�x�/?�@�@�� � � �$4�4�4� �!1�2�:�:�<�<�5��$�%5�6�7�7�3�t�9�9�D�D� �F��)�)�'�/�:�:�� � %� %�&6� 7� 7���N�N�7�;�/�/� �� � �=�y�I�I�I��� �� � ��H� �L�L�9� :� :� :� �� � ��H� �L�L�8� 9� 9� 9� � )�� ���y�1�1� )� �L�L�K� L� L� L� �J� � �i� (� (� (� � � �F� �"�&�&�v�r�2�2� 2� 2� �L�L�8� 9� 9� 9� �F� � � ��*:� :� :� �L�L�.� /� /� /� �J�N�N��4�?�0�0��(��0�N�N� � � � � � �_�� #� #� �L�L�5� 6� 6� 6� �J�N�N�9�d�o�&;�&;�G�X�&N�&N� O� O� O� O� O� �'� '� '��B���2�i�=�1�#4�#4�� � �F�G�G�G�� ����t��4�4�W�h�T�4�R�R������ �.�.�.�#�I�.���L�L�!@�A�A�A��J�N�N�!�4�?�#8�#8��(�QU�#8�#V�#V������(� '�/�.��rc���|�|j��}|j�||j�|����}|s|Sdg�|j�t�fd�|j� ��D������d|_ |j� ||j� ||����|S)z�On a 304 we will get a new set of headers that we want to update our cached value with, assuming we have one. This should only ever be called when we've sent an ETag and gotten a 304 as the response. roc3�R�K�|]!\}}|����v�||fV��"dSr1)r%)�.0�k�v�excluded_headerss �r� z9CacheController.update_cached_response..ksK��������A�q��7�7�9�9�$4�4�4��A��4�4�4�4��rr) r2rUrrVrr>rG�update�dict�itemsrXrurv)rr^rwr2�cached_responser�s @r�update_cached_responsez&CacheController.update_cached_responseRs�����N�N�7�;�/�/� ��/�/�/������ �9R�9R�S�S��� ��O�-�-����&�&� �����$�,�2�2�4�4���� � � � � �"%��� � ���y�$�/�"7�"7���"Q�"Q�R�R�R��r)NTNN)NN) rF� __module__� __qualname__�__doc__r � classmethodr/r2rPrirmr{r��rrrrs���������KO�K�K�K�K�����[��&�!�!��[�!�4�4�4�lm�m�m�^��� Y�Y�Y�Y�v&�&�&�&�&rr)r��logging�rer[rZ� email.utilsr�pip._vendor.requests.structuresrrr� serializer� getLoggerrFrB�compiler r�objectrr�rr�r�s��������� � � � ����� � � � �$�$�$�$�$�$�?�?�?�?�?�?�������!�!�!�!�!�!� �� �8� $� $���b�j�M�N�N��C�C�C�Z�Z�Z�Z�Z�f�Z�Z�Z�Z�Zr