
    h                         d dl Z d dlZd dl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 ZddZd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)    N)timezone)
LazyObject)import_string)Image)settingsc           
      &   t        | t        j                        sy| j                         }t        t	        |            }|D cg c]  }||z  	 }}t	        |D cg c]!  }|dk7  s	|t        j                  |d      z  # c}       S c c}w c c}w )zG
    Calculate the entropy of an image. Used for "smart cropping".
    r      )
isinstancer   	histogramfloatsummathlog)imhist	hist_sizehps        E/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/utils.pyimage_entropyr      s{     b%++&<<>Dc$i I#'(aA	M(D(T<Q!VTXXa^#<=== )<s   B	
B&Bc                 8   | It        t        j                        t        t        j                        z   D cg c]  }t	        |       } }t        g d      }| D ].  }t        j                  |      d   }|j                  |dd        0 t        |      S c c}w )zm
    Return a list of unique valid options for a list of image processors
    (and/or source generators)
    N)sizequalitysubsamplingr      )
tupler   THUMBNAIL_PROCESSORSTHUMBNAIL_SOURCE_GENERATORSr   setinspectgetfullargspecupdatelist)
processorsr   valid_options	processorargss        r   valid_processor_optionsr(      s    
  (//0(66789!"M!9
 9 :;M '	%%i03T!"X&' 9s   Bc                 F    	 | j                  d       y# t        $ r Y yw xY w)z2
    Check to see if a file storage is local.
    testFT)pathNotImplementedError)storages    r   is_storage_localr.   ,   s,    V   s    	  c                 0   t        | t              r(| j                  | j                          | j                  } t        | t              s'| j
                  }|j                  d|j                  } t        | j                  d            j                         S )z
    Return a hex string hash for a storage object (or string containing
    'full.path.ClassName' referring to a storage object).
    .utf8)r
   r   _wrapped_setupstr	__class__
__module____name__md5_not_used_for_securityencode	hexdigest)r-   storage_clss     r   get_storage_hashr<   7   sw     ':&#NN""gs#''(33[5I5IJ$W^^F%;<FFHH    c                     t        | t        j                        sy| j                  dv xs | j                  dk(  xr d| j                  v S )z2
    Check to see if an image is transparent.
    F)RGBALAPtransparency)r
   r   modeinfoimages    r   is_transparentrG   G   sI     eU[[) JJ.( AZZ3?>UZZ#?Br=   c                 t    t        | t        j                        syd| j                  v xs d| j                  v S )z2
    Check to see if an image is progressive.
    Fprogressiveprogression)r
   r   rD   rE   s    r   is_progressiverK   S   s2     eU[[)UZZ'I]ejj-HIr=   c                    	 t         j                  }	 | j                         }|r/|j                  d      }|dk(  r| j                  |j                        } | S |dk(  r| j                  |j                        } | S |dk(  r| j                  |j                        } | S |dk(  r6| j                  |j                        j                  |j                        } | S |dk(  r| j                  |j                        } | S |dk(  r6| j                  |j                        j                  |j                        } | S |d	k(  r| j                  |j                        } | S # t        $ r
 t         }Y Ww xY w# t        $ r d}Y Xw xY w)
zS
    Rotate and/or flip an image to respect the image's EXIF orientation data.
    Ni  r	                     )r   	TransposeAttributeError_getexif	Exceptionget	transposeFLIP_LEFT_RIGHT
ROTATE_180FLIP_TOP_BOTTOM
ROTATE_270	ROTATE_90)r   Image__Transposeexiforientations       r   exif_orientationra   ]   s   
! ??
{{}
 hhv&!.>>?B I A.99:B I A.>>?B I A.99:I.>>?  I A.99:B I A.889I.>>?  I A.889BI9  ! !   s"   E E- E*)E*-E<;E<c                     	 | j                  |      }|rPt        j                  |      r;t        t        dd      r*t        j                         }t        j                  ||      S |S # t        $ r Y yt        $ r Y yw xY w)z_
    Get modified time from storage, ensuring the result is a timezone-aware
    datetime.
    r   NUSE_TZF)	get_modified_timeOSErrorr,   r   is_naivegetattrr   get_default_timezone
make_aware)r-   namemodified_timedefault_timezones       r   rd   rd      s}    
11$7
 **=98Xu-'<<>&&}6FGG   s   A' '	A=2A=<A=c                 2    t        j                  d| d      S )z
    Calculate a md5 hash of the given data, but explicitly mark it as not
    being used for security purposes. Without this flag FIPS compliant
    systems will raise an exception when used.
    md5Fusedforsecurityhashlibnewdatas    r   r8   r8      s     ;;udE::r=   c                 2    t        j                  d| d      S )z
    Calculate a sha1 hash of the given data, but explicitly mark it as not
    being used for security purposes. Without the flag FIPS compliant
    systems will raise an exception when used.
    sha1Fro   rq   rt   s    r   sha1_not_used_for_securityrx      s     ;;vtU;;r=   )N)rr   r    r   django.utilsr   django.utils.functionalr   django.utils.module_loadingr   PILr   easy_thumbnails.confr   r   r(   r.   r<   rG   rK   ra   rd   r8   rx    r=   r   <module>r      sS       ! . 5  )
>$I 	BJ$N";<r=   