
    )jM                     H    d dl Z d dlmZ d Zd	dZd Z G d d          ZdS )
    N)Pathc                 v   t          j                    }t          d          }t          |          }t	          | dd          5 }|                    |          x}r4|                    |d|                    |                    |          x}4ddd           n# 1 swxY w Y   |                                S )zReturn the hex digest of a filei   rbr   )	bufferingN)hashlibsha256	bytearray
memoryviewopenreadintoupdate	hexdigest)	file_pathhbmvfns         W/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trame_client/utils/web_module.pyfile_digestr      s    A*A	AB	i	+	+	+ q::b>>!a 	HHRV ::b>>!a 	               ;;==s   ABB #B (   c                    t          |           } |t          |           }t          |          |k    r
|d|         }|                     | j         d| | j                   }|                    |                                            |S )zEWrite a new file sibbling to file_path with a digest hash in his nameN-)r   r   len	with_namestemsuffixwrite_bytes
read_bytes)r   digestdigest_sizeoutput_files       r   file_with_digestr#      s    YI~Y''
6{{[  % %%&T&T&&T)BR&T&TUUKI0022333    c                 z    |                                  d |D             }t          fd|D                       S )z7Helper to check that *other_paths are nested under pathc                 P    g | ]#}t          |                                          $S  )r   resolve).0others     r   
<listcomp>z"is_relative_to.<locals>.<listcomp>%   s*    FFFtE{{**,,FFFr$   c              3   l   K   | ].}j         d t          |j                            |j         k    V  /d S N)partsr   )r)   baseabs_paths     r   	<genexpr>z!is_relative_to.<locals>.<genexpr>(   sP        <@(TZ()TZ7     r$   )r(   all)pathother_pathsabs_other_pathsr0   s      @r   is_relative_tor6   !   s_     ||~~HFF+FFFO     DS     r$   c                   N    e Zd ZdZddZd Zd Zd Zd Zd	 Z	e
d
             ZdS )	WebModulez{Helper class to create/define a module while dynamically computing hash
    to properly prevent invalid browser cache.
    N   c                     || _         g | _        i | _        g | _        g | _        g | _        || j                            |           d S d S r-   )_digest_size_serving_entries_serve_vue_use_styles_scriptsappend)selfvue_user!   s      r   __init__zWebModule.__init__2   sX    ' "M  ))))) r$   c                 r   t          |                                          }|                                st          d| d          | j        D ]V}|\  }}t          ||          r?| j        dk    rt          || j                  }|                    |          }| d| c S Wt          d|           )NzFile z does not existr   )r!   /zNo parent found for )	r   r(   exists
ValueErrorr<   r6   r;   r#   relative_to)rB   r   entryfs_pathwww_pathr_paths         r   	_add_filezWebModule._add_file=   s    OO++--	!! 	A?Y???@@@* 		. 		.E %GXi11 .$q(( 0!t/@! ! !I #..w77"--V-----. ;	;;<<<r$   c                 T   t          |                                          }|                                st          d| d          || j        v r#t          d| d| j        |          d|           | j                            ||f           t          |          | j        |<   dS )z9Register a new directory to serve with its alias endpointz
Directory z+ does not exist - Won't be able to serve itz
Entry for z is already set for zand want to override with N)r   r(   rG   rH   r=   r<   rA   str)rB   directory_to_servewww_base_namerK   s       r   serve_directoryzWebModule.serve_directoryO   s    )**2244~~ 	QWQQQ   DK''7] 7 7M@Z 7 7-47 7  
 	$$g}%=>>>%(\\M"""r$   c                 `    | j                             |                     |                     dS )zWAdd a script file to serve while computing unique name and proper http path internally.N)r@   rA   rN   rB   r   s     r   add_script_filezWebModule.add_script_file_   s*    T^^I6677777r$   c                 `    | j                             |                     |                     dS )zTAdd a css file to serve while computing unique name and proper http path internally.N)r?   rA   rN   rU   s     r   add_style_filezWebModule.add_style_filec   s*    DNN95566666r$   c                 :    | j                             |           dS )z Register a vue plugin expressionN)r>   rA   )rB   rC   s     r   add_vue_usezWebModule.add_vue_useg   s    W%%%%%r$   c                 P    t          | j        | j        | j        | j                  S )z2Return the generated trame module as a dictionary.)servescriptsstylesrC   )dictr=   r@   r?   r>   )rB   s    r   modulezWebModule.modulek   s/     +M<M	
 
 
 	
r$   )Nr9   )__name__
__module____qualname____doc__rD   rN   rS   rV   rX   rZ   propertyr`   r'   r$   r   r8   r8   -   s         	* 	* 	* 	*= = =$2 2 2 8 8 87 7 7& & & 
 
 X
 
 
r$   r8   )Nr   )r   pathlibr   r   r#   r6   r8   r'   r$   r   <module>rg      s               "	 	 	F
 F
 F
 F
 F
 F
 F
 F
 F
 F
r$   