
    ceZ                        U d Z ddlmZ dgZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddZ G d d          Z eej                  Zded<   dS )zUtilities to manage resources.    )annotationsload_resourceN)http_loggerlogger)configurlstrreturntyping.Optional[bytes]c                X   	 t          j        | d          }t          j        |           |                                 t
                              | |j                   |j        S # t           j        $ r2 t          j
        d|            t
                              |           cY S w xY w)zFetch external resource.   )timeout)responsezUnable to fetch resource: %s)requestsgetr   httpraise_for_statusCACHEstorecontentRequestExceptionr   	exception)r   r   s     Nlib/python3.11/site-packages/anaconda_navigator/utils/attribution/resources.pyr   r      s    &.l3&C&C&C(++++!!###C)***$   7===yy~~s   A%A( (>B)(B)c                  ^    e Zd ZdZdZddZedd            Zdd
ZddZ	ddZ
ddZddZdS )Cachez Class manipulate with cache data)	__content__rootrootr	   r
   Nonec                    || _         i | _        t          j        | j         d           |                                  dS )z(Initialize new :class:`~Cache` instance.T)exist_okN)_Cache__root_Cache__contentosmakedirs_load)selfr   s     r   __init__zCache.__init__$   s8    )-02
DK$////

    c                L    t           j                            | j        d          S )zPath to the cache index file.zcache_mapping.jsonr$   pathjoinr"   )r'   s    r   __index_pathzCache.__index_path-   s     w||DK)=>>>r)   keyc                R    t           j                            | j        d|           S )z&Prepare path to the cache record file.cache_data_r+   )r'   r/   s     r   __record_pathzCache.__record_path2   s#    w||DK)<s)<)<===r)   c                   	 t          | j        dd          5 }t          j        |          | _        ddd           dS # 1 swxY w Y   dS # t
          $ r Y dS t          j        t          f$ r t          j	        d           Y dS w xY w)z<Loading mapping data from mapping.json into content variablertutf-8encodingNzcache index is broken)
open_Cache__index_pathjsonloadr#   FileNotFoundErrorJSONDecodeErrorOSErrorr   debugr'   streams     r   r&   zCache._load6   s    	2d'AAA 3V!%6!2!23 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3  	 	 	DD$g. 	2 	2 	2L0111111	2s9   A A A  AA AA 
B)BBc                    	 t          | j        dd          5 }t          j        | j        |d           ddd           dS # 1 swxY w Y   dS # t
          $ r t          j        d           Y dS w xY w)z<Save mapping data from self.__context into json mapping filewtr5   r6   F)ensure_asciiNzunable to update cache index)r8   r9   r:   dumpr#   r>   r   r?   r@   s     r   _savezCache._saveA   s    	9d'@@@ FF	$.&uEEEEF F F F F F F F F F F F F F F F F F 	9 	9 	9L7888888	9s3   A AA AA 
AA A21A2databytesc                v   	 | j         |         }nF# t          $ r9 t          j                    j        x}| j         |<   |                                  Y nw xY w	 t          |                     |          d          5 }|                    |           ddd           dS # 1 swxY w Y   dS # t          $ r Y dS w xY w)z)Save data into json data file by uuid keywbN)
r#   KeyErroruuiduuid4hexrF   r8   _Cache__record_pathwriter>   )r'   r/   rG   
record_keyrA   s        r   r   zCache.storeJ   s   	,JJ 	 	 	/3z||/??J,JJLLLLL		d((44d;; #vT"""# # # # # # # # # # # # # # # # # # 	 	 	DD	sF    A AA#B* :BB* B!!B* $B!%B* *
B87B8r   c                    	 t          |                     | j        |                   d          5 }|                                cddd           S # 1 swxY w Y   dS # t          t
          f$ r Y dS w xY w)zGet cache data by keyrbN)r8   rO   r#   readrK   r>   )r'   r/   rA   s      r   r   z	Cache.getZ   s    	d(()<==tDD %{{}}% % % % % % % % % % % % % % % % % %'" 	 	 	44	s4   .A AA AA AA A32A3N)r   r	   r
   r   )r
   r	   )r/   r	   r
   r	   )r
   r   )r/   r	   rG   rH   r
   r   )r/   r	   r
   r   )__name__
__module____qualname____doc__	__slots__r(   propertyr9   rO   r&   rF   r   r    r)   r   r   r      s        **'I    ? ? ? X?> > > >	2 	2 	2 	29 9 9 9         r)   r   )r   ztyping.Final[Cache]r   )r   r	   r
   r   )rX   
__future__r   __all__r:   r$   typingrL   r   anaconda_navigator.utils.logsr   r   anaconda_navigatorr   navigator_configr   r   AD_CACHEr   __annotations__r[   r)   r   <module>rd      s    % $ $ " " " " " "
  				    = = = = = = = = 9 9 9 9 9 9
 
 
 
B B B B B B B BJ #U(8(ABBB B B B B B Br)   