
    hj                     R    d dl Z d dlmZ d dlmZ d Zd Zd Z G d d      Zg d	Z	y)
    N)Path)to_mimec                 4    t        |       j                         S )z
    Return the text content of the file path

    :param file_path: Path to the file to read
    :type file_path: str

    :return: File content
    :rtype: str
    )r   	read_text	full_paths    F/DATA/.local/lib/python3.12/site-packages/trame_common/assets/local.pyto_txtr
      s     	?$$&&    c                 x    t        j                  t        |       j                               j	                  d      S )z
    Return the base64 content of the file path

    :param file_path: Path to the file to read
    :type file_path: str

    :return: File content encoded in base64
    :rtype: str
    ascii)base64	b64encoder   
read_bytesdecoder   s    r	   	to_base64r      s-     DO6689@@IIr   c                 >    t        |       }t        |       }d| d| S )z
    Return the base64 encoded URL of the file path

    :param file_path: Path to the file to read
    :type file_path: str

    :return: Inlined bas64 encoded url (data:{mime};base64,{content})
    :rtype: str
    zdata:z;base64,)r   r   )r   encodedmimes      r	   to_urlr   !   s+     	"G9D4&	**r   c                   R    e Zd ZdZd Zd Zd Zd ZddZd Z	d	 Z
ed
        Zd Zy)LocalFileManagerzDLocalFileManager provide convenient methods for handling local filesc                     t        |      }|j                         r|j                  }t        t        |j	                         j                                     | _        i | _        y)z
        Provide the base path on which relative path should be based on.

        :param base_path: A file or directory path
        :type base_path: str
        N)r   is_fileparentstrresolveabsolute_root_assests)self	base_path_bases      r	   __init__zLocalFileManager.__init__3   sH     Y ==?LLE#emmo6689:
r   c                 8    | j                   j                  |      S Nr    getr!   names     r	   __getitem__zLocalFileManager.__getitem__C       }}  &&r   c                 8    | j                   j                  |      S r&   r'   r)   s     r	   __getattr__zLocalFileManager.__getattr__F   r,   r   c                    t        |      }|j                         r't        |j                         j	                               S t        | j
                  j                  |      j                         j	                               S r&   )r   is_absoluter   r   r   r   joinpath)r!   	file_path_input_files      r	   _to_pathzLocalFileManager._to_pathI   s`    9o""${**,557884::&&y199;DDFGGr   Nc                 h    |||}}t        | j                  |            }||| j                  |<   |S )ac  
        Store a base64 file content under the provided key name

        :param key: name for that content which can then be accessed
                    by the [] or . notation
        :type key: str

        :param file_path: A file or directory path
        :type file_path: str

        :return: Return the stored content
        :rtype: str
        )r   r4   r    r!   keyr2   datas       r	   r   zLocalFileManager.base64P   s>      )sIy12?!%DMM#r   c                 h    |||}}t        | j                  |            }||| j                  |<   |S )ah  
        Store a url encoded file content under the provided key name

        :param key: name for that content which can then be accessed
                    by the [] or . notation
        :type key: str

        :param file_path: A file or directory path
        :type file_path: str

        :return: Return the stored content
        :rtype: str
        )r   r4   r    r6   s       r	   urlzLocalFileManager.urlh   >      )sIdmmI./?!%DMM#r   c                 h    |||}}t        | j                  |            }||| j                  |<   |S )ac  
        Store a file content (text) under the provided key name

        :param key: name for that content which can then be accessed
                    by the [] or . notation
        :type key: str

        :param file_path: A file or directory path
        :type file_path: str

        :return: Return the stored content
        :rtype: str
        )r
   r4   r    r6   s       r	   txtzLocalFileManager.txt   r;   r   c                     | j                   S )z'Return the full set of assets as a dict)r    )r!   s    r	   assetszLocalFileManager.assets   s     }}r   c                     t        |      dk(  r| j                  S i }|D ]   }| j                  j                  |      ||<   " |S )z9Return a filtered out dict using the provided set of keysr   )lenr?   r    r(   )r!   keys_assetsr7   s       r	   
get_assetszLocalFileManager.get_assets   sE    t9>;;C==,,S1GCL  r   r&   )__name__
__module____qualname____doc__r$   r+   r.   r4   r   r:   r=   propertyr?   rD    r   r	   r   r   0   sB    N ''H000  	r   r   )r   r   r   r
   r   )
r   pathlibr   trame_common.assets.mimetypesr   r
   r   r   r   __all__rJ   r   r	   <module>rN      s2      1
'
J+v vrr   