
    hH                         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  G d de      Zdd	Zdd
Z	 	 ddZddZy)    N)BytesIOStringIO)import_stringImage)settings)ThumbnailOptionsc                       e Zd ZdZd Zy)NoSourceGeneratorzZ
    Exception that is raised if no source generator can process the source
    file.
    c                 J    dj                  t        | j                              S )Nz+Tried {0} source generators with no success)formatlenargs)selfs    F/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/engine.py__str__zNoSourceGenerator.__str__   s     <CC		N 	    N)__name__
__module____qualname____doc__r    r   r   r   r      s    
r   r   c                     t        |      }|&t        j                  D cg c]  }t        |       }}| }|D ]  } ||fi |} |S c c}w )zy
    Process a source PIL image through a series of image processors, returning
    the (potentially) altered image.
    )r	   r   THUMBNAIL_PROCESSORSr   )sourceprocessor_options
processorsnameimage	processors         r   process_imager!      sp    
 )):; !557 $7
 7 E 6	%5#456L7s   Ac                    |
t               }|xs d}t        j                          t        j                  j	                  t
        j                  j                  |      d   j                         d      }|t        j                  v r;t        j                  |   j                         D ]  \  }}|j                  ||        d}|dk(  r| j                  j                  d      r| j                  | j                  dd       } t        j                   r+t#        | j$                        t        j                   k\  rd|d	<   	 |j'                  d
d      r| j(                  j	                  d      |d<    | j*                  |f|dd| d}n|dk7  rd|v r|j'                  d       |s | j*                  |fd|i| t/        |d      r|j1                  d       |S # t,        $ r Y Aw xY w)z
    Save a PIL image.
    N    JPEGFATprogressivekeep_icc_profileicc_profile)r   optimizeWEBPqualityr   seekr   )r   r   init	EXTENSIONgetospathsplitextlowerr   THUMBNAIL_IMAGE_SAVE_OPTIONSitems
setdefaultmodeendswithconvertTHUMBNAIL_PROGRESSIVEmaxsizepopinfosaveIOErrorhasattrr.   )r   destinationfilenameoptionsr   keyvaluesaveds           r   save_pil_imagerJ   (   s    i~2H	JJL__  !1!1(!;A!>!D!D!FOF666"??GMMO 	+JCsE*	+E::s# MM%**Sb/2E))EJJ8#A#AA%)GM"
	{{-u5).)F&EJJ{I6AIIE V	W 4KK	"

;9v99{F#  	
 	s   >AG 	G#"G#c                    t        |      }t        | dd      }|&t        j                  D cg c]  }t	        |       }}g }	 |D ]9  }| }	 |j                          	  ||fi |}	|	s#|	c |r	 | j                          S S  	 |r	 | j                          |r|st        | yyc c}w # t        $ r' 	 |j                  d       n# t        $ r d}Y nw xY wY |w xY w# t        $ r.}
|s t        |      dk(  r |j                  |
       d}	Y d}
~
d}
~
ww xY w# t        $ r Y S w xY w# t        $ r Y w xY w# |r!	 | j                          w # t        $ r Y w w xY ww xY w)aH  
    Processes a source ``File`` through a series of source generators, stopping
    once a generator returns an image.

    The return value is this image instance or ``None`` if no generators
    return an image.

    If the source file cannot be opened, it will be set to ``None`` and still
    passed to the generators.
    closedFNr   r$   )r	   getattrr   THUMBNAIL_SOURCE_GENERATORSr   open	Exceptionr.   r   appendcloser   )source_filer   
generatorsfail_silently
was_closedr   
exceptions	generatorr   r   es              r   generate_source_imagerZ   S   s    )):; h6J !<<> $>
 > J# 	I F"!&>,=>  !!# 3	2 !!# -,, (zG>  ""KKN  "!F""  $:!+%%a(  9  !!#  s   B$D4 B)	C&D4 )D4 /DD4 D% )	C3CCCCCCD4 CD4 	D%$D	D4 DD4 	D"!D"%	D10D14E8E	E		EEEEc                     ddl m} |
t               } | j                  |fddi| t	        |d      r|j                  d       |S )z
    Save a SVG image.
    r   r   r   SVGr.   )easy_thumbnails.VILr   r   rA   rC   r.   )r   rD   rE   rF   r   s        r   save_svg_imager^      sJ     *jEJJ{454G4{F#r   )N)NN)NT)r2   ior   r   django.utils.module_loadingr   PILr   easy_thumbnails.confr   easy_thumbnails.optionsr	   rP   r   r!   rJ   rZ   r^   r   r   r   <module>rd      sC    	   5  ) 4	  (V FJ(,5-pr   