
    ~+hO                         d Z ddlmZ ddlZddlZddlZddlmZ ddlZddlm	Z	m
Z
 ddlmZ ddlmZ dZ G d	 d
e      Z G d de      Zy)zHelpers for testing webassets.

This is included in the webassets package because it is useful for testing
external libraries that use webassets (like the flask-assets wrapper).
    )print_functionN)path)EnvironmentBundle)map)zip)TempDirHelperTempEnvironmentHelperc                   l    e Zd ZdZi Zd Zd Zd Zd Ze	d        Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zy)r	   zBase-class for tests which provides a temporary directory
    (which is properly deleted after the test is done), and various
    helper methods to do filesystem operations within that directory.
    c                 l    t        j                         | _        | j                  | j                         y N)tempfilemkdtemp_tempdir_createdcreate_filesdefault_filesselfs    A/var/www/html/venv/lib/python3.12/site-packages/webassets/test.pysetupzTempDirHelper.setup   s'     ( 0 0 2$,,-    c                 B    t        j                  | j                         y r   )shutilrmtreer   r   s    r   teardownzTempDirHelper.teardown"   s    d++,r   c                 &    | j                          | S r   )r   r   s    r   	__enter__zTempDirHelper.__enter__%   s    

r   c                 $    | j                          y r   )r   )r   typevalue	tracebacks       r   __exit__zTempDirHelper.__exit__)   s    r   c                     | j                   S r   )r   r   s    r   tempdirzTempDirHelper.tempdir,   s    
 $$$r   c                    ddl }t        |d      st        t        d |            }|j	                         D ]  \  }}t        j                  | j                  |            }t        j                  |      st        j                  |       |j                  | j                  |      dd      }|j                  |       |j                           y)zvHelper that allows to quickly create a bunch of files in
        the media directory of the current test run.
        r   Nitemsc                 
    | dfS N  )ns    r   <lambda>z,TempDirHelper.create_files.<locals>.<lambda>:   s
    2w r   wzutf-8)codecshasattrdictr   r&   r   dirnameexistsosmakedirsopenwriteclose)r   filesr.   namedatadirsfs          r   r   zTempDirHelper.create_files3   s     	ug&.67E++- 	JD$<<		$0D;;t$D!DIIdOS':AGGDMGGI	r   c                     g }|D ]9  }| j                  |      }|j                  |       t        j                  |       ; |S )zkHelper to create directories within the media directory
        of the current test's environment.
        )r   appendr3   r4   )r   r;   resultdir	full_paths        r   create_directoriesz TempDirHelper.create_directoriesC   sD      	#C		#IMM)$KK	"	# r   c                 J    t        j                  | j                  |            S )z\Ensure the given file exists within the current test run's
        media directory.
        )r   r2   r   r9   s     r   r2   zTempDirHelper.existsN   s     {{499T?++r   c                     t        | j                  |            5 }|j                         }t        t	        |             |cddd       S # 1 sw Y   yxY w)z*Return the given file's contents.
        N)r5   r   readprintrepr)r   r9   r<   rs       r   getzTempDirHelper.getT   sD     $))D/" 	aA$q'N	 	 	s   &AAc                 L    t        j                  | j                  |             y r   )r3   unlinkr   rD   s     r   rL   zTempDirHelper.unlink\   s    
		$))D/"r   c                 B    t        j                  | j                  |      S )z"Return the given file's full path.)r   joinr   rD   s     r   r   zTempDirHelper.path_   s    yy..55r   c                 &   |j                  dt        j                               }||j                  dd      z  }|r'J ddj                  |j                               z         |D ])  }t	        j
                  | j                  |      ||f       + |S )ac  Set the mtime of the given files. Useful helper when
        needing to test things like the timestamp updater.

        Specify ``mtime`` as a keyword argument, or time.time()
        will automatically be used. Returns the mtime used.

        Specify ``mod`` as a keyword argument, and the modifier
        will be added to the ``mtime`` used.
        mtimemodr   zUnsupported kwargs: %sz, )poptimerN   keysr3   utimer   )r   r8   kwargsrP   r<   s        r   setmtimezTempDirHelper.setmtimec   s     

7DIIK0E1%%O3tyy7OOOz 	3AHHTYYq\E5>2	3r   c                     |sdg}|D ]^  }| j                  |      }t        |       t        dt        |      z         t        t        |             t        |       t                ` y)zbPrint the contents of the given files to stdout; useful
        for some quick debugging.
        out-N)rJ   rG   lenrH   )r   r8   r<   contents       r   pzTempDirHelper.pt   sY     GE 	AhhqkG!H#A,$w- 'NG	r   N)__name__
__module____qualname____doc__r   r   r   r   r"   propertyr$   r   rB   r2   rJ   rL   r   rW   r]   r*   r   r   r	   r	      s^    
 M.- % % 	,#6"r   r	   c                   0    e Zd ZdZdddddZd Zd Zd	 Zy
)r
   zBase-class for tests which provides a pre-created
    environment, based in a temporary directory, and utility
    methods to do filesystem operations within that directory.
    ABCD)in1in2in3in4c                     t         j                  |        | j                         | _        d| j                  _        d| j                  _        y )NF)r	   r   _create_environmentenvcachemanifestr   s    r   r   zTempEnvironmentHelper.setup   s9    D!++- !r   c                 .    t        | j                  d      S r(   )r   r   r   s    r   rm   z)TempEnvironmentHelper._create_environment   s    400"55r   c                 >    t        |i |}| j                  |_        |S r   )r   rn   )r   akwbs       r   mkbundlezTempEnvironmentHelper.mkbundle   s!    Ar   N)r^   r_   r`   ra   r   r   rm   rv   r*   r   r   r
   r
      s&    
  CDM"6r   r
   )ra   
__future__r   r   r   r3   r   rS   	webassetsr   r   webassets.six.movesr   r   __all__objectr	   r
   r*   r   r   <module>r|      sI   
 &   	   ) # # 6jF jZM r   