
    h                         d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ e G d	 d
e             Ze G d de             Z G d de
      Zy)    N)BytesIOStringIO)ContentFile)FileSystemStorage)TestCase)deconstructible)import_string)settingsc                   *     e Zd ZdZd fd	Zd Z xZS )TemporaryStoragez
    A storage class useful for tests that uses a temporary location to store
    all files and provides a method to remove this location when it is finished
    with.
    c                 b    |t        j                         }|| _        t        |   |d|i| y)z0
        Create the temporary location.
        Nlocation)tempfilemkdtemptemporary_locationsuper__init__)selfr   argskwargs	__class__s       K/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/tests/utils.pyr   zTemporaryStorage.__init__   s8     '')H&.D#T<(<V<    c                 N    t        | dd      }|rt        j                  |       yy)z
        Delete the temporary directory created during initialisation.
        This storage class should not be used again after this method is
        called.
        r   N)getattrshutilrmtree)r   r   s     r   delete_temporary_storagez)TemporaryStorage.delete_temporary_storage   s)     %T+?FMM,- r   )N)__name__
__module____qualname____doc__r   r   __classcell__r   s   @r   r   r      s    =.r   r   c                   N     e Zd ZdZdZ fdZ fdZ fdZ fdZ fdZ	 xZ
S )FakeRemoteStoragezc
    A temporary storage class that acts similar to remote storage.

    It's not thread safe.
    Fc                 F    | j                   rt        t        |   |i |S )z
        Raise ``NotImplementedError``, since this is the way that
        easy-thumbnails determines if a storage is remote.
        )remote_modeNotImplementedErrorr   pathr   r   r   r   s      r   r*   zFakeRemoteStorage.path3   s(    
 %%w|T,V,,r   c                 p    | j                   }d| _         	 t        |   |i ||| _         S # || _         w xY w)NF)r(   r   exists)r   r   r   original_remote_moder   s       r   r-   zFakeRemoteStorage.exists<   s?    #// 	47>42623D3Ds   , 	5c                 X    d| _         	 t        |   |i |d| _         S # d| _         w xY wNFT)r(   r   saver+   s      r   r1   zFakeRemoteStorage.saveD   2     	$7<00#DtD     	)c                 X    d| _         	 t        |   |i |d| _         S # d| _         w xY wr0   )r(   r   openr+   s      r   r5   zFakeRemoteStorage.openK   r2   r3   c                 X    d| _         	 t        |   |i |d| _         S # d| _         w xY wr0   )r(   r   deleter+   s      r   r7   zFakeRemoteStorage.deleteR   s2     	$7>4262#DtDr3   )r   r    r!   r"   r(   r*   r-   r1   r5   r7   r#   r$   s   @r   r&   r&   *   s-    
 K-4$$$ $r   r&   c                   8     e Zd ZdZ fdZ fdZ	 	 ddZ xZS )BaseTestz
    Remove any customised THUMBNAIL_* settings in a project's ``settings``
    configuration module before running the tests to ensure there is a
    consistent test environment.
    c                 :    t         |          }dt        _        |S )z'
        Isolate all settings.
        T)r   setUpr
   isolated)r   outputr   s     r   r;   zBaseTest.setUpa   s      r   c                 ^    dt         _        t        j                          t        |          S )z;
        Restore settings to their original state.
        F)r
   r<   revertr   tearDown)r   r   s    r   r@   zBaseTest.tearDowni   s%     "w!!r   c                 D   |dk(  rddl m} t               }nddlm} t	               }|j                  ||      5 }|j                  ||       ddd       |j                  d       |s|S t        |j                               }	|j                  ||	      }
|
S # 1 sw Y   KxY w)z
        Generate a test image, returning the filename that it was saved as.

        If ``storage`` is ``None``, the BytesIO containing the image data
        will be passed instead.
        SVGr   )ImageN)
easy_thumbnails.VILrC   r   PILr   newr1   seekr   read)r   storagefilenamesize
image_modeimage_formatrC   dataimg
image_filestorage_files              r   create_imagezBaseTest.create_imageq   s     5 1:D!9DYYz4( 	)CHHT<(	)		!K -
||Hj9	) 	)s   BB))i   iX  RGBJPEG)r   r    r!   r"   r;   r@   rR   r#   r$   s   @r   r9   r9   Z   s    " 4>4:r   r9   )r   r   ior   r   django.core.files.baser   django.core.files.storager   django.testr   django.utils.deconstructr   django.utils.module_loadingr	   easy_thumbnails.confr
   r   r&   r9    r   r   <module>r]      se        . 7   4 5 ) .( . .6 ,$( ,$ ,$^,x ,r   