
    3j=>                     |   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ  e ed            ZeeefZeeehZeeee ed      hZe	j:                  e	j<                  e	j>                  e	j@                  e	jB                  hZ"ee#eee$e%hez  e"z  Z&ee#eee%hez  Z'd Z(d Z)d	 Z*d
 Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4d Z5d Z6d Z7d Z8d Z9d Z:d Z;d Z<d Z=d Z>d Z?d Z@d  ZAd! ZBd" ZCd0d#ZDd0d$ZEd% ZFd& ZGd' ZHd( ZId) ZJd* ZKd+ ZLd, ZMd- ZN ej                  d      fd.ZOd1d/ZPy)2zkHelper functions for pickling and unpickling.  Most functions assist in
determining the type of an object.
    N)Iterator   )tags c                 "    t        | t              S )zReturns True is obj is a reference to a type.

    >>> is_type(1)
    False

    >>> is_type(object)
    True

    >>> class Klass: pass
    >>> is_type(Klass)
    True
    )
isinstancetypeobjs    </DATA/.local/lib/python3.12/site-packages/jsonpickle/util.pyis_typer   9   s     c4      c                 "   t        | |      syt        | |      }t        |t        j                        ryt        |t        j
                  t        j                  f      syt        |       r| n| j                  }d }t        j                  |      D ]   }t        |      j                  |      }|  n |yt        |t              ryt        |d      syt        |d      }t        |t              rt        ||      S t        | t!        |            S )NFT__self__)hasattrgetattrr   typesBuiltinMethodType
MethodTypeFunctionTyper   	__class__inspectgetmrovarsgetstaticmethodclassmethod
issubclassr	   )r   namefunc	base_typeoriginalsubtypebound_tos          r   
has_methodr%   J   s    33D $//0 dU--u/A/ABC s|IH>>),=$$T* -  (L) 4$tZ(H (K()X.. c4>**r   c                     t        | t              xr0 t        | t        t        j                  t        j
                  f       S )zReturns True is obj is a reference to an object instance.

    >>> is_object(1)
    True

    >>> is_object(object())
    True

    >>> is_object(lambda x: 1)
    False
    )r   objectr	   r   r   BuiltinFunctionTyper
   s    r   	is_objectr)   y   s<     c6" :dE&&(A(AB, ( r   c                 $    t        |       t        v S )zfDetermines if the object is not a class or a class instance.
    Used for serializing properties.
    )r	   NON_CLASS_TYPESr
   s    r   is_not_classr,      s     9''r   c                 $    t        |       t        v S )a  Helper method to see if the object is a basic data type. Unicode strings,
    integers, longs, floats, booleans, and None are considered primitive
    and will return True when passed into *is_primitive()*

    >>> is_primitive(3)
    True
    >>> is_primitive([4,4])
    False
    )r	   
PRIMITIVESr
   s    r   is_primitiver/      s     9
""r   c                 x    dt         j                  v xr' t        | t         j                  d   j                        S )zIs the object an enum?enum)sysmodulesr   Enumr
   s    r   is_enumr5      s,    S[[ NZS[[5H5M5M%NNr   c                 X    t        j                  dt               t        |       t        u S )zoHelper method for testing if the object is a dictionary.

    >>> is_dictionary({'key':'value'})
    True

    [This function will be removed in the next release of jsonpickle, 5.0.0! Please migrate now.)warningswarnDeprecationWarningr	   dictr
   s    r   is_dictionaryr<      s'     MMe 9r   c                 $    t        |       t        v S )zpHelper method to see if the object is a sequence (list, set, or tuple).

    >>> is_sequence([4])
    True

    )r	   SEQUENCES_SETr
   s    r   is_sequencer?      s     9%%r   c                 X    t        j                  dt               t        |       t        u S )zXHelper method to see if the object is a Python list.

    >>> is_list([4])
    True
    r7   )r8   r9   r:   r	   listr
   s    r   is_listrB      s'     MMe 9r   c                 X    t        j                  dt               t        |       t        u S )zXHelper method to see if the object is a Python set.

    >>> is_set(set())
    True
    r7   )r8   r9   r:   r	   setr
   s    r   is_setrE      s'     MMe 9r   c                 X    t        j                  dt               t        |       t        u S )z[Helper method to see if the object is a bytestring.

    >>> is_bytes(b'foo')
    True
    r7   )r8   r9   r:   r	   bytesr
   s    r   is_bytesrH      '     MMe 9r   c                 X    t        j                  dt               t        |       t        u S )zBDEPRECATED: Helper method to see if the object is a unicode stringr7   )r8   r9   r:   r	   strr
   s    r   
is_unicoderL      s%    MMe 9r   c                 X    t        j                  dt               t        |       t        u S )z[Helper method to see if the object is a Python tuple.

    >>> is_tuple((1,))
    True
    r7   )r8   r9   r:   r	   tupler
   s    r   is_tuplerO      rI   r   c                 x    t        | d      xr- t        | j                  t              xr t	        |       t        uS )zReturns True if *obj* is a subclass of the dict type. *obj* must be
    a subclass and not the actual builtin dict.

    >>> class Temp(dict): pass
    >>> is_dictionary_subclass(Temp())
    True
    r   )r   r   r   r;   r	   r
   s    r   is_dictionary_subclassrQ      s7     	[! 	"s}}d+	"IT!r   c                 n    t        | d      xr( t        | j                  t              xr t	        |        S )zReturns True if *obj* is a subclass of list, set or tuple.

    *obj* must be a subclass and not the actual builtin, such
    as list, set, tuple, etc..

    >>> class Temp(list): pass
    >>> is_sequence_subclass(Temp())
    True
    r   )r   r   r   	SEQUENCESr?   r
   s    r   is_sequence_subclassrT     s6     	[! 	!s}}i0	!C  r   c                 <    t        |       t        j                  u ryy)zReturns True if *obj* is a special (weird) class, that is more complex
    than primitive data types, but is not a full object. Including:

        * :class:`~time.struct_time`
    TF)r	   timestruct_timer
   s    r   is_noncomplexrX     s     CyD$$$r   c                 $    t        |       t        v S )zReturns true if passed a function

    >>> is_function(lambda x: 1)
    True

    >>> is_function(locals)
    True

    >>> def method(): pass
    >>> is_function(method)
    True

    >>> is_function(1)
    False
    )r	   FUNCTION_TYPESr
   s    r   is_functionr[   $  s      9&&r   c                     t        | d      xrW t        | t        j                  t        j                  f      xr+ t        | d      xr t        | d      xr | j
                  dk7  xs t        |       S )zReturn True if `obj` is a module-global function

    >>> import os
    >>> is_module_function(os.path.exists)
    True

    >>> is_module_function(lambda: None)
    False

    r   
__module____name__z<lambda>)r   r   r   r   r(   r^   is_cython_functionr
   s    r   is_module_functionr`   7  su     	[! 	'sU//1J1JKL	'C&	' C$	' LLJ&! 
C	 !r   c                 j    t        j                  dt               t        | t        j
                        S )zWReturns True if passed a module

    >>> import os
    >>> is_module(os)
    True

    r7   )r8   r9   r:   r   r   
ModuleTyper
   s    r   	is_modulerc   L  s+     MMe c5++,,r   c                 Z    | t         j                  v ryt        |      xs t        |       S )zReturn True if an object can be pickled

    >>> import os
    >>> is_picklable('os', os)
    True

    >>> def foo(): pass
    >>> is_picklable('foo', foo)
    True

    >>> is_picklable('foo', lambda: None)
    False

    F)r   RESERVEDr`   r[   )r   values     r   is_picklablerg   [  s+     t}}e$>K,>(>>r   c                 :    	 t        |        y# t        $ r Y yw xY w)zTests to see if ``module`` is available on the sys.path

    >>> is_installed('sys')
    True
    >>> is_installed('hopefullythisisnotarealmodule')
    False

    TF)
__import__ImportErrormodules    r   is_installedrm   o  s$    6 s    	c                 6    t        | d      xr t        | d      S )N__getitem__append)r   r
   s    r   is_list_likerq     s    3&A73+AAr   c                 \    t        | t              xr t        | t        j                         S N)r   abc_iteratorioIOBaser
   s    r   is_iteratorrw     s"    c<(KC1K-KKr   c                 R    	 t        |       j                  dk(  S # t        $ r Y yw xY w)NcollectionsF)r	   r]   	Exceptionr
   s    r   is_collectionsr{     s.    Cy##}44 s    	&&c                 R    t        | d      xr t        | j                  t              S )Nr   )r   r   r   rS   r
   s    r   is_reducible_sequence_subclassr}     s    3$MCMM9)MMr   c                 d   t        |       rt        | t        j                        syt	        |       t
        v sx| t        u spt        |       set        | t        j                        sKt        |       s@t        |       s5t        t        | dd      t              st        |       r| j                  dk(  ryy)zu
    Returns false if of a type which have special casing,
    and should not have their __reduce__ methods used
    T	__slots__NdatetimeF)r{   r   ry   defaultdictr	   NON_REDUCIBLE_TYPESr'   rQ   r   rb   r}   rq   r   _ITERATOR_TYPEr   r]   r
   s    r   is_reducibler     s     c:c;3J3J#KS	((&=!#&c5++,)#.gc;5~FCLS^^z9r   c                 l    t        |       xr( t        | d      xr t        |       j                  d      S )z>Returns true if the object is a reference to a Cython function__repr__z<cyfunction )callabler   repr
startswithr
   s    r   r_   r_     s6     	 	1C$	1I  0r   c                 R    	 t        | ||       y# t        $ r Y yt        $ r Y yw xY w)NFT)setattrAttributeError	TypeError)r   attrrf   s      r   is_readonlyr     s5    	T5!   s    	&&&c                 <    t        | dd      r|| j                  v S |S )zt
    Returns true if key exists in obj.__dict__; false if not in.
    If obj.__dict__ is absent, return default
    __dict__N)r   r   r   keydefaults      r   in_dictr     s#    
 %,CT$BC3<<OOr   c                 <    t        | dd      r|| j                  v S |S )zv
    Returns true if key exists in obj.__slots__; false if not in.
    If obj.__slots__ is absent, return default
    r   N)r   r   r   s      r   in_slotsr     s#    
 &-S+t%DC3== Q'Qr   c                    t        |       rt        |       ryt        |       ryd}d}d}d}t        | |      xs t	        | |      }t        | |      xs t	        | |      }t        |       j                  D ]8  }t        |      r |xs t        ||      }|xs t        ||      }|s1|s4||fc S  t        |       }t        t        |      }t        t        |      }|st        ||d      }	|	|ur|	}|st        ||d      }
|
|ur|
}||fS )z
    Tests if __reduce__ or __reduce_ex__ exists in the object dict or
    in the class dicts of every class in the MRO *except object*.

    Returns a tuple of booleans (has_reduce, has_reduce_ex)
    )FF)FTF
__reduce____reduce_ex__)	r   r   rX   r   r   r	   __mro__r   r'   )r   
has_reducehas_reduce_exREDUCE	REDUCE_EXbaseclsobject_reduceobject_reduce_exhas_reduce_clshas_reduce_ex_clss              r   r   r     s%    
 SJMFI f%>#v)>JC+GxY/GM S	!!#<wtV'<J)EWT9-EM-.. " s)CFF+Mvy1 fe4.'J#CE:$44-M&&r   c                 @    t        dd      }|j                  | |       S )a  Rename builtin modules to a consistent module name.

    Prefer the more modern naming.

    This is used so that references to Python's `builtins` module can
    be loaded in both Python 2 and 3.  We remap to the "__builtin__"
    name and unmap it when importing.

    Map the Python2 `exceptions` module to `builtins` because
    `builtins` is a superset and contains everything that is
    available in `exceptions`, which makes the translation simpler.

    See untranslate_module_name() for the reverse operation.
    builtins__builtin__
exceptionsr;   r   rl   lookups     r   translate_module_namer     s!     jZ@F::ff%%r   c                 @    t        dd      }|j                  | |       S )zProvide compatibility for pickles created with jsonpickle 0.9.6 and
    earlier, remapping `exceptions` and `__builtin__` to `builtins`.
    r   r   r   r   s     r   _0_9_6_compat_untranslater     s!     jZ@F::ff%%r   c                     t        |       S )zRename module names mention in JSON to names that we can import

    This reverses the translation applied by translate_module_name() to
    a module name available to the current version of Python.

    )r   rk   s    r   untranslate_module_namer     s     %V,,r   c                    t        | d| j                        }t        | j                        }|sYt	        | d      rMt	        | j
                  d      r| j
                  j                  }n | j
                  j                  j                  }| d| S )a  
    >>> class Example(object):
    ...     pass

    >>> ex = Example()
    >>> importable_name(ex.__class__) == 'jsonpickle.util.Example'
    True
    >>> importable_name(type(25)) == 'builtins.int'
    True
    >>> importable_name(None.__class__) == 'builtins.NoneType'
    True
    >>> importable_name(False.__class__) == 'builtins.bool'
    True
    >>> importable_name(AttributeError) == 'builtins.AttributeError'
    True

    __qualname__r   r]   .)r   r^   r   r]   r   r   r   )r   r   rl   s      r   importable_namer   )  st    & 35D"3>>2F3
#s||\200//::XQtfr   c                 J    t        j                  |       j                  d      S )zI
    Encode binary data to ascii text in base64. Data must be bytes.
    ascii)base64	b64encodedecodedatas    r   r   r   G        D!((11r   c                 l    	 t        j                  |       S # t        t        j                  f$ r Y yw xY wz.
    Decode payload - must be ascii text.
    r   )r   	b64decoder   binasciiErrorpayloads    r   r   r   N  s3    ((x~~& s    33c                 J    t        j                  |       j                  d      S )zI
    Encode binary data to ascii text in base85. Data must be bytes.
    r   )r   	b85encoder   r   s    r   r   r   X  r   r   c                 X    	 t        j                  |       S # t        t        f$ r Y yw xY wr   )r   	b85decoder   
ValueErrorr   s    r   r   r   _  s/    ((z" s    ))c                 $    t         ||             S rs   )rK   )r   getters     r   
itemgetterr   i  s    vc{r   c              #   R   K   | j                         D ]  \  }}||v r||f  yw)zt
    This can't be easily replaced by dict.items() because this has the exclude parameter.
    Keep it for now.
    N)items)r   excludekvs       r   r   r   m  s/     
 		1<d
 s   %')F) )Q__doc__r   r   ry   r   ru   operatorr2   rV   r   r8   collections.abcr   rt   r   r   r	   iterr   rA   rD   rN   rS   r>   rK   boolintfloatr.   r   r   
LambdaTyper(   r   rZ   r;   r'   rG   r   r+   r   r%   r)   r,   r/   r5   r<   r?   rB   rE   rH   rL   rO   rQ   rT   rX   r[   r`   rc   rg   rm   rq   rw   r{   r}   r   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s       	  
    4 d2h3	sE"4eT$Z0
					 	  	  			 !",+^"(
#O
&



 "'&!*-?( BLN,PR2'j&&&-<22 /8..q1 r   