
    %^g*                     ^    d dl Z d dlmZ d dlmZmZmZ d dlmZm	Z	 d	dZ
d Z G d d      Zy)
    N)settings)ThumbnailErrordeserialize	serialize)deserialize_image_fileserialize_image_filec                 F    dj                  t        j                  || g      S )z"
    Adds prefixes to the key
    ||)joinr   THUMBNAIL_KEY_PREFIX)keyidentitys     `/var/www/html/webapps/promises/venv/lib/python3.12/site-packages/sorl/thumbnail/kvstores/base.py
add_prefixr      s      99h33XsCDD    c                 *    | j                  d      d   S )z'
    Removes prefixes from the key
    r
   )split)r   s    r   
del_prefixr      s     99T?2r   c                   ~    e Zd Zd Zd ZddZd ZddZd Zd Z	d	 Z
d
 ZddZddZddZddZd Zd Zd Zd Zy)KVStoreBasec                 X    t        | dd      st        j                  dt        d       y y )N_cached_db_kvstoreFzUsing any other KVStore than Cached Db KVStore is deprecated. Please configure the cache that suits your use case at Django level and set this cache alias in THUMBNAIL_CACHE.   )
stacklevel)getattrwarningswarnDeprecationWarning)selfs    r   __init__zKVStoreBase.__init__   s.    t159MME # :r   c                 8    | j                  |j                        S )zT
        Gets the ``image_file`` from store. Returns ``None`` if not found.
        )_getr   )r    
image_files     r   getzKVStoreBase.get!   s     yy((r   Nc                    |j                          | j                  |j                  |       || j                  |      st	        d|j
                  z        | j                  |j                  d      xs g }t        |      }|j                  |j                         | j                  |j                  t        |      d       yy)zi
        Updates store for the `image_file`. Makes sure the `image_file` has a
        size set.
        Nz>Cannot add thumbnails for source: `%s` that is not in kvstore.
thumbnailsr   )
set_size_setr   r%   r   namer#   setaddlist)r    r$   sourcer'   s       r   r,   zKVStoreBase.set'   s    
 			*..*-88F#$ &?AG&M N N 6::EKJZJNN:>>*IIfjj$z"2\IJ r   c                 R    | j                  |      }||S | j                  |       |S N)r%   r,   )r    r$   cacheds      r   
get_or_setzKVStoreBase.get_or_set;   s-    *%Mr   c                 `    |r| j                  |       | j                  |j                         y)z
        Deletes the reference to the ``image_file`` and deletes the references
        to thumbnails as well as thumbnail files if ``delete_thumbnails`` is
        `True``. Does not delete the ``image_file`` is self.
        N)delete_thumbnails_deleter   )r    r$   r5   s      r   deletezKVStoreBase.deleteB   s%     "":.Z^^$r   c                     | j                  |j                  d      }|r[|D ]8  }| j                  |      }|s| j                  |d       |j                          : | j                  |j                  d       yy)zX
        Deletes references to thumbnails as well as thumbnail ``image_files``.
        r'   r(   FN)r#   r   r7   r6   )r    r$   thumbnail_keysr   	thumbnails        r   r5   zKVStoreBase.delete_thumbnailsL   ss     :>>LI & ' IIcN	KK	51$$&	' LL,L? r   c                     | j                  d      D ]C  }| j                  |d      }|s|D ]&  }| j                  |      }|s|j                          ( E y )Nr'   r(   )
_find_keysr#   r7   )r    r   r9   r:   s       r   delete_all_thumbnail_filesz&KVStoreBase.delete_all_thumbnail_files^   s\    ??L?9 	+C!YYs\YBN) +C $		#I !((*+	+r   c                    | j                  d      D ]8  }| j                  |      }|s|j                         r(| j                  |       : | j                  d      D ]  }| j                  |      }|rn| j                  |d      xs g }t	        |      }|D ]%  }| j                  |      r|j                  |       ' t        |      }|r| j                  ||d       | j                  |d        y)a  
        Cleans up the key value store. In detail:
        1. Deletes all key store references for image_files that do not exist
           and all key references for its thumbnails *and* their image_files.
        2. Deletes or updates all invalid thumbnail keys
        imager(   r'   N)	r<   r#   existsr7   r,   remover.   r*   r6   )r    r   r$   r9   thumbnail_keys_setthumbnail_keys         r   cleanupzKVStoreBase.cleanupg   s     ??G?4 	(C3J*"3"3"5J'		( ??L?9 	5C 3J "&3!F!L"%(%8"%3 AM99]3*11-@A "&&8!9!IIc>LII
 LL|L41	5r   c                 f    | j                  t        j                        }|r | j                  |  yy)z
        Brutely clears the key value store for keys with THUMBNAIL_KEY_PREFIX
        prefix. Use this in emergency situations. Normally you would probably
        want to use the ``cleanup`` method instead.
        N)_find_keys_rawr   r   _delete_raw)r    all_keyss     r   clearzKVStoreBase.clear   s2     &&x'D'DEDh' r   c                 t    | j                  t        ||            }|sy|dk(  rt        |      S t        |      S )z<
        Deserializing, prefix wrapper for _get_raw
        Nr?   )_get_rawr   r   r   )r    r   r   values       r   r#   zKVStoreBase._get   s=     jh78w)%005!!r   c                 t    |dk(  rt        |      }nt        |      }| j                  t        ||      |       y)z:
        Serializing, prefix wrapper for _set_raw
        r?   N)r   r   _set_rawr   )r    r   rL   r   ss        r   r*   zKVStoreBase._set   s5     w$U+A% Ajh/3r   c                 :    | j                  t        ||             y)z0
        Prefix wrapper for _delete_raw
        N)rG   r   )r    r   r   s      r   r6   zKVStoreBase._delete   s     	C23r   c              #   v   K   t        d|      }| j                  |      xs g }|D ]  }t        |        yw)z:
        Finds and returns all keys for identity,
         N)r   rF   r   )r    r   prefixraw_keysraw_keys        r   r<   zKVStoreBase._find_keys   sC      B)&&v.4" 	&GW%%	&s   79c                     t               )zL
        Gets the value from keystore, returns `None` if not found.
        NotImplementedError)r    r   s     r   rK   zKVStoreBase._get_raw        "##r   c                     t               )z
        Sets value associated to key. Key is expected to be shorter than 200
        chars. Value is a ``unicode`` object with an unknown (reasonable)
        length.
        rW   )r    r   rL   s      r   rN   zKVStoreBase._set_raw   s     "##r   c                     t               )zD
        Deletes the keys. Silent failure for missing keys.
        rW   )r    keyss     r   rG   zKVStoreBase._delete_raw   rY   r   c                     t               )z,
        Finds all keys with prefix
        rW   )r    rS   s     r   rF   zKVStoreBase._find_keys_raw   rY   r   r1   )Tr?   )__name__
__module____qualname__r!   r%   r,   r3   r7   r5   r=   rD   rI   r#   r*   r6   r<   rK   rN   rG   rF    r   r   r   r      sZ    )K(%@$+%5N("44&$$$$r   r   r^   )r   sorl.thumbnail.confr   sorl.thumbnail.helpersr   r   r   sorl.thumbnail.imagesr   r   r   r   r   rb   r   r   <module>rf      s+     ( I I NED$ D$r   