
    3~h                          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
 ddlmZmZ dd	lmZmZ dd
lmZmZmZ  G d d      Z G d de      Zd Zd Z G d d      Zy)    )copy)settings)ImageFieldFile   )hashers)get_default_cachefile_backend)load_strategy)AlreadyRegisteredMissingSource)generator_registryregister)get_by_qname
open_imageprocess_imagec                   F    e Zd ZdZdZ	 dZ	 ej                  Z	 d Z	d Z
eZy)BaseImageSpecz_
    An object that defines how an new image should be generated from a source
    image.

    Nc                 r    | j                   xs
 t               | _         t        | j                        | _        y N)cachefile_backendr   r	   cachefile_strategyselfs    `/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/imagekit/specs/__init__.py__init__zBaseImageSpec.__init__'   s,    !%!7!7!Z;X;Z"/0G0G"H    c                     t         r   )NotImplementedErrorr   s    r   generatezBaseImageSpec.generate+   s    !!r   )__name__
__module____qualname____doc__cachefile_storager   r   #IMAGEKIT_DEFAULT_CACHEFILE_STRATEGYr   r   r   r    r   r   r   r      sG     > "EEI" "Mr   r   c                        e Zd ZdZg Z	 dZ	 dZ	 dZ	  fdZe	d        Z
e	d        Zej                  d        Zd Zd	 Zd
 Z xZS )	ImageSpecz
    An object that defines how to generate a new image from a source file using
    PIL-based processors. (See :mod:`imagekit.processors`)

    NTc                 0    || _         t        | 	          y r   )sourcesuperr   )r   r)   	__class__s     r   r   zImageSpec.__init__X   s    r   c                 `    | j                   sy t        t        j                  d      } ||       S )Nnamer)r)   r   r   IMAGEKIT_SPEC_CACHEFILE_NAMER)r   fns     r   cachefile_namezImageSpec.cachefile_name\   s'    {{(@@'J$xr   c                 x    t        | dd       }|s*t        | dd       }|rt        |d   |d         x}| _        | `|S )N_source_field_datainstanceattname)getattrr2   r3   )r   src
field_datas      r   r)   zImageSpec.sourcec   sM    dIt, }d;J%,Z
-CZPYEZ%[[dl$
r   c                     || _         y r   )r2   )r   values     r   r)   zImageSpec.sourcem   s	    r   c                    t        | j                        }t        | j                  t              rP| j                  j
                  }t        | j                  dd       t        |dd       d|d<   |j                  dd        |S )Nr4   name)r4   r5   r3   r2   )r   __dict__
isinstancer)   r   fieldr6   pop)r   stater?   s      r   __getstate__zImageSpec.__getstate__q   sl    T]]# dkk>2KK%%E#DKKTB"5&$7$E-  IIi&r   c                     t        j                  | j                  j                  | j                  | j
                  | j                  | j                  g      S r   )r   pickler)   r<   
processorsformatoptionsautoconvertr   s    r   get_hashzImageSpec.get_hash   sC    ~~KKOOKKLL
  	r   c                    | j                   st        d| z        | j                   j                  }|r| j                   j                          	 t	        | j                         }t        || j                  | j                  | j                  | j                        }|r| j                   j                          |S # |r| j                   j                          w w xY w)Nz4The spec '%s' has no source file associated with it.)rE   rF   rH   rG   )r)   r   closedopenr   r   rE   rF   rH   rG   close)r   rK   img	new_images       r   r   zImageSpec.generate   s    {{ !,.2!3 4 4 ## KK
	$T[[)C%c15-1[[262B2B.2ll	<I !!# !!# s   AB9 9C)r   r    r!   r"   rE   rF   rG   rH   r   propertyr0   r)   setterrB   rI   r   __classcell__)r+   s   @r   r'   r'   6   s     J<F G K     ]] *r   r'   c                 B      G  fddt               }t        d|f       S )Nc                       e Zd Z fdZy)*create_spec_class.<locals>.DynamicSpecBasec                 v    	 | j                   } |       }t        |ffS # t        $ r | j                  }Y !w xY wr   )rB   AttributeErrorr=   create_spec)r   getstaterA   class_attrss      r   
__reduce__z5create_spec_class.<locals>.DynamicSpecBase.__reduce__   sF    #,, !
+u!566	 " &&s     88N)r   r    r!   r[   )rZ   s   r   DynamicSpecBaserU      s    	7r   r\   DynamicSpec)r'   type)rZ   r\   s   ` r   create_spec_classr_      s#    7) 7 1;??r   c                     t        |       }|j                  |      }	 |j                  } ||       |S # t        $ r ||_        Y |S w xY wr   )r_   __new____setstate__rW   r=   )rZ   rA   clsr4   setstates        r   rX   rX      sX    
K
(C{{3H(( 	O	  "! O	"s   4 AAc                   $    e Zd ZdZddZd Zd Zy)SpecHostzh
    An object that ostensibly has a spec attribute but really delegates to the
    spec registry.

    Nc                     |j                         D ci c]  \  }}|	|| }}}|r|rt        d      t        |      }|| _        |r| j	                  |       y y c c}}w )Nz^You can provide either an image spec or arguments for the ImageSpec constructor, but not both.)items	TypeErrorr_   _original_specset_spec_id)r   specspec_idkwargskv
spec_attrss          r   r   zSpecHost.__init__   sr    '-||~Gtq!adG
G !N O O )4"W%  Hs
   
AAc                     || _         | j                  r"	 t        j                  || j                         yy# t        $ r Y yw xY w)a[  
        Sets the spec id for this object. Useful for when the id isn't
        known when the instance is constructed (e.g. for ImageSpecFields whose
        generated `spec_id`s are only known when they are contributed to a
        class). If the object was initialized with a spec, it will be registered
        under the provided id.

        N)rm   rj   r   	generatorr
   )r   ids     r   rk   zSpecHost.set_spec_id   sJ     ""2t':':;  %  s    7 	AAc                 z    t        | dd      st        d| z        t        j                  | j                  |      S )a  
        Look up the spec by the spec id. We do this (instead of storing the
        spec as an attribute) so that users can override apps' specs--without
        having to edit model definitions--simply by registering another spec
        with the same id.

        rm   NzObject %s has no spec id.)r)   )r6   	Exceptionr   getrm   )r   r)   s     r   get_speczSpecHost.get_spec   s8     tY-7$>??!%%dll6BBr   )NN)r   r    r!   r"   r   rk   rx   r%   r   r   rf   rf      s    
& ,
Cr   rf   N)r   django.confr   django.db.models.fields.filesr    r   cachefiles.backendsr   cachefiles.strategiesr	   
exceptionsr
   r   registryr   r   utilsr   r   r   r   r'   r_   rX   rf   r%   r   r   <module>r      sT       8  ? 1 9 3 ; ;% %Ps sl@	6C 6Cr   