
    'j                     Z    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	dS )
    N)Path)to_mimec                 D    t          |                                           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    S/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trame_common/assets/local.pyto_txtr
      s     	??$$&&&    c                     t          j        t          |                                                                         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      s5     DOO668899@@IIIr   c                 N    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   !   s4     	""G9D*4*****r   c                   Z    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dS )LocalFileManagerzDLocalFileManager provide convenient methods for handling local filesc                     t          |          }|                                r|j        }t          t          |                                                                                    | _        i | _        dS )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   s^     Y ==?? 	!LE#emmoo668899::
r   c                 6    | j                             |          S Nr    getr!   names     r	   __getitem__zLocalFileManager.__getitem__C       }  &&&r   c                 6    | j                             |          S r&   r'   r)   s     r	   __getattr__zLocalFileManager.__getattr__F   r,   r   c                 D   t          |          }|                                r3t          |                                                                          S t          | j                            |                                                                                    S r&   )r   is_absoluter   r   r   r   joinpath)r!   	file_path_input_files      r	   _to_pathzLocalFileManager._to_pathI   s}    9oo""$$ 	9{**,,55778884:&&y1199;;DDFFGGGr   Nc                 n    |||}}t          |                     |                    }|
|| 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   sB      )sIy1122?!%DM#r   c                 n    |||}}t          |                     |                    }|
|| 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   B      )sIdmmI..//?!%DM#r   c                 n    |||}}t          |                     |                    }|
|| 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                            |          ||<    |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   sM    t99>>; 	2 	2C=,,S11GCLLr   r&   )__name__
__module____qualname____doc__r$   r+   r.   r4   r   r:   r=   propertyr?   rD    r   r	   r   r   0   s        NN   ' ' '' ' 'H H H   0  0  0   X	 	 	 	 	r   r   )r   r   r   r
   r   )
r   pathlibr   trame_common.assets.mimetypesr   r
   r   r   r   __all__rJ   r   r	   <module>rN      s           1 1 1 1 1 1
' 
' 
'
J 
J 
J+ + +v v v v v v v vr  r   