
    (phH                          S SK JrJr  S SKJr  S SKJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S	S
KJr   " S S\5      r " S S5      rS rS rSS jrSS jr " S S\R8                  5      rg)    )	b64decode	b64encode)deepcopy)dumpsloads)compress
decompress)settings)checks)models)	force_str   )DEFAULT_PROTOCOLc                       \ rS rSrSrSrg)PickledObject   a  
A subclass of string so it can be told whether a string is a pickled
object or not (if the object is an instance of this class then it must
[well, should] be a pickled one).

Only really useful for passing pre-encoded values to ``default``
with ``dbsafe_encode``, not that doing so is necessary. If you
remove PickledObject and its references, you won't be able to pass
in pre-encoded values anymore, but you can always just pass in the
python objects themselves.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       E/var/www/html/venv/lib/python3.13/site-packages/picklefield/fields.pyr   r      s    
r   r   c                   "    \ rS rSrSrSrS rSrg)_ObjectWrapper   a#  
A class used to wrap object that have properties that may clash with the
ORM internals.

For example, objects with the `prepare_database_save` property such as
`django.db.Model` subclasses won't work under certain conditions and the
same apply for trying to retrieve any `callable` object.
_objc                     Xl         g Nr   )selfobjs     r   __init___ObjectWrapper.__init__'   s    	r   N)r   r   r   r   r   	__slots__r%   r   r   r   r   r   r      s     Ir   r   c                 ^    [        U S5      (       d  [        U 5      (       a  [        U 5      n U $ )Nprepare_database_save)hasattrcallabler   )r$   s    r   wrap_conflictual_objectr,   +   s'    s+,,S!Jr   c                  ,    [        [        S[        5      $ )NPICKLEFIELD_DEFAULT_PROTOCOL)getattrr
   r   r   r   r   get_default_protocolr0   1   s    8;=MNNr   Nc                     Uc
  [        5       nU(       a  [        U 5      n [        XS9n U(       a  [        U 5      n [	        U 5      R                  5       n [        U 5      $ )N)protocol)r0   r   r   r   r   decoder   )valuecompress_objectpickle_protocolcopys       r   dbsafe_encoder8   5   sT     .0 %2Ee##%Er   c                 r    U R                  5       n [        U 5      n U(       a  [        U 5      n [        U 5      $ r"   )encoder   r	   r   )r4   r5   s     r   dbsafe_decoder;   I   s.    LLNEeE5!<r   c                      ^  \ rS rSrSrSrU 4S jrU 4S jrS rU 4S jr	U 4S jr
S	 rU 4S
 jrS rSS jrS rS rU 4S jrSrU =r$ )PickledObjectFieldQ   ap  
A field that will accept *any* python object and store it in the
database. PickledObjectField will optionally compress its values if
declared with the keyword argument ``compress=True``.

Does not actually encode and compress ``None`` objects (although you
can still do lookups using None). This way, it is still possible to
use the ``isnull`` lookup type correctly.
Fc                    > UR                  SS5      U l        UR                  SS 5      nUc
  [        5       nX0l        UR                  SS5      U l        UR                  SS5        [        TU ]  " U0 UD6  g )Nr   Fr2   r7   Teditable)popr   r0   r2   r7   
setdefaultsuperr%   )r#   argskwargsr2   	__class__s       r   r%   PickledObjectField.__init__]   sl    

:u5::j$/+-H JJvt,	*e,$)&)r   c                    > U R                  5       (       a6  [        U R                  5      (       a  U R                  5       $ U R                  $ [        TU ]  5       $ )a  
Returns the default value for this field.

The default implementation on models.Field calls force_unicode
on the default, which means you can't set arbitrary Python
objects as the default. To fix this, we just return the value
without calling force_unicode on it. Note that if you set a
callable as a default, the field will still call it. It will
*not* try to pickle and encode it.

)has_defaultr+   defaultrC   get_default)r#   rF   s    r   rK   PickledObjectField.get_defaultg   sG     %%||~%<<w"$$r   c                 D   U R                  5       (       a  [        U R                  [        [        [
        45      (       a`  [        R                  " U R                  R                  < S3S[        U R                  5      R                  < SU R                  < S3U SS9/$ / $ )Nzp default should be a callable instead of a mutable instance so that it's not shared between all field instances.z#Use a callable instead, e.g., use `z` instead of `z`.zpicklefield.E001)hintr$   id)rI   
isinstancerJ   listdictsetr   WarningrF   r   typer#   s    r   _check_default!PickledObjectField._check_defaultz   s    *T\\D$;L"M"M // !.77 LL ) $ Ir   c                 f   > [         TU ]  " S0 UD6nUR                  U R                  5       5        U$ )Nr   )rC   checkextendrW   )r#   rE   errorsrF   s      r   rZ   PickledObjectField.check   s.    ((d))+,r   c                    > [         TU ]  5       u  pp4U R                  (       a  SUS'   U R                  [	        5       :w  a  U R                  US'   XX44$ )NTr   r2   )rC   deconstructr   r2   r0   )r#   namepathrD   rE   rF   s        r   r_   PickledObjectField.deconstruct   sO    #(7#6#8 D==!%F:==022!%F:4''r   c                     Ub:   [        XR                  5      n[        U[        5      (       a  UR                  $  U$ U$ ! [
         a    [        U[        5      (       a  e  U$ f = f)a,  
B64decode and unpickle the object, optionally decompressing it.

If an error is raised in de-pickling and we're sure the value is
a definite pickle, the error is allowed to propagate. If we
aren't sure if the value is a pickle or not, then we catch the
error and return the original value instead.

)r;   r   rP   r   r    	Exceptionr   )r#   r4   s     r   	to_pythonPickledObjectField.to_python   ss     	&%e]]; e^44 ::% 5u   e]33 4
 s   A    A$#A$c                 8   > [         TU ]  X5      n[        U5      $ r"   )rC   pre_saver,   )r#   model_instanceaddr4   rF   s       r   rh   PickledObjectField.pre_save   s     5&u--r   c                 $    U R                  U5      $ r"   )re   )r#   r4   
expression
connections       r   from_db_value PickledObjectField.from_db_value   s    ~~e$$r   c                     UbI  [        U[        5      (       d4  [        [        XR                  U R
                  U R                  5      5      nU$ )aP  
Pickle and b64encode the object, optionally compressing it.

The pickling protocol is specified explicitly (by default 2),
rather than as -1 or HIGHEST_PROTOCOL, because we don't want the
protocol to change over time. If it did, ``exact`` and ``in``
lookups would likely fail, since pickle would now be generating
a different string.

)rP   r   r   r8   r   r2   r7   )r#   r4   rn   prepareds       r   get_db_prep_value$PickledObjectField.get_db_prep_value   s?     Z}%E%E mE==$--QUQZQZ[\Er   c                 F    U R                  U5      nU R                  U5      $ r"   )value_from_objectrs   )r#   r$   r4   s      r   value_to_string"PickledObjectField.value_to_string   s#    &&s+%%e,,r   c                     g)N	TextFieldr   rV   s    r   get_internal_type$PickledObjectField.get_internal_type   s    r   c                 J   > US;  a  [        SU-  5      e[        TU ]	  U5      $ )z$
We need to limit the lookup types.
)exactinisnullz Lookup type %s is not supported.)	TypeErrorrC   
get_lookup)r#   lookup_namerF   s     r   r   PickledObjectField.get_lookup   s/     77>LMMw!+..r   )r   r7   r2   )NF)r   r   r   r   r   empty_strings_allowedr%   rK   rW   rZ   r_   re   rh   ro   rs   rw   r{   r   r   __classcell__)rF   s   @r   r=   r=   Q   sQ     "*%&,
(..%*-/ /r   r=   )FNT)F)base64r   r   r7   r   pickler   r   zlibr   r	   django.confr
   django.corer   	django.dbr   django.utils.encodingr   	constantsr   strr   r   r,   r0   r8   r;   Fieldr=   r   r   r   <module>r      s]    '   %     + 'C  O (L/ L/r   