o
    tBh8                     @   sB  d Z ddlmZmZm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 ddlmZmZmZmZmZmZmZ erPddlZeeefZeeehZejeedheeB Z ej!ej"ej#ej$ej%hZ&e'e(ee)eee*e+he B e&B Z,dd	 Z-d
d Z.dd Z/dd Z0dd Z1dd Z2dd Z3dd Z4dd Z5dd Z6dd Z7dd Z8d d! Z9d"d# Z:d$d% Z;d&d' Z<d(d) Z=d*d+ Z>d,d- Z?d.d/ Z@d0d1 ZAd2d3 ZBd4d5 ZCd6d7 ZDd8d9 ZEdUd;d<ZFdUd=d>ZGd?d@ ZHdAdB ZIdCdD ZJdEdF ZKdGdH ZLdIdJ ZMdKdL ZNdMdN ZOdOdP ZPeQdfdQdRZQdSdT ZRdS )VzkHelper functions for pickling and unpickling.  Most functions assist in
determining the type of an object.
    )absolute_importdivisionunicode_literalsN   )tags)compat)abc_iteratorclass_typesiterator_typesnumeric_typesPY2PY3PY3_ORDERED_DICTc                 C   s
   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
    )
isinstancer	   obj r   f/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/jsonpickle/util.pyis_type>   s   
r   c                 C   s   t | |sdS t| |}t|tjrdS t|tjtjfsdS t| r%| n| j}d }t	
|D ]}t||}|d ur> nq/|d u rEdS t|trLdS trPdnd}t ||sYdS t||}t|trht||S t| t|S )NFT__self__im_self)hasattrgetattrr   typesBuiltinMethodType
MethodTypeFunctionTyper   	__class__inspectgetmrovarsgetstaticmethodr   classmethod
issubclasstype)r   namefunc	base_typeoriginalsubtype	self_attrbound_tor   r   r   
has_methodO   s2   






r-   c                 C   s    t | to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   r   r   r   	is_object   s   r0   c                 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   r   r   r   is_primitive   s   
r3   c                 C   s   dt jv ot| t jd jS )zIs the object an enum?enum)sysmodulesr   Enumr   r   r   r   is_enum   s   r8   c                 C      t | tu S )zoHelper method for testing if the object is a dictionary.

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

    )r%   dictr   r   r   r   is_dictionary      r;   c                 C   r1   )zpHelper method to see if the object is a sequence (list, set, or tuple).

    >>> is_sequence([4])
    True

    )r%   SEQUENCES_SETr   r   r   r   is_sequence   r<   r>   c                 C   r9   )zXHelper method to see if the object is a Python list.

    >>> is_list([4])
    True
    )r%   listr   r   r   r   is_list      r@   c                 C   r9   )zXHelper method to see if the object is a Python set.

    >>> is_set(set())
    True
    )r%   setr   r   r   r   is_set   rA   rC   c                 C   r9   )z[Helper method to see if the object is a bytestring.

    >>> is_bytes(b'foo')
    True
    )r%   bytesr   r   r   r   is_bytes   rA   rE   c                 C   s   t | tju S )z6Helper method to see if the object is a unicode string)r%   r   ustrr   r   r   r   
is_unicode   s   rG   c                 C   r9   )z[Helper method to see if the object is a Python tuple.

    >>> is_tuple((1,))
    True
    )r%   tupler   r   r   r   is_tuple   rA   rI   c                 C   s"   t | dot| jto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   r   r   r   is_dictionary_subclass   s
   



rJ   c                 C   s(   t | dot| jtpt| o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   	SEQUENCESis_list_liker>   r   r   r   r   is_sequence_subclass   s
   
rM   c                 C   s   t | tju r	dS dS )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   r   r   r   is_noncomplex   s   rP   c                 C   r1   )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   r   r   r   is_function  s   rR   c                 C   s:   t | dot| tjtjfot | dot | do| jdk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/   rT   r   r   r   r   is_module_function  s   
rU   c                 C   s   t | tjS )zWReturns True if passed a module

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

    )r   r   
ModuleTyper   r   r   r   	is_module3  s   rW   c                 C   s    | t jv rdS t|p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   RESERVEDrU   rR   )r&   valuer   r   r   is_picklable>  s   
rZ   c                 C   s$   zt |  W dS  ty   Y dS w )zTests to see if ``module`` is available on the sys.path

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

    TF)
__import__ImportError)moduler   r   r   is_installedR  s   	r^   c                 C   s   t | do	t | dS )N__getitem__append)r   r   r   r   r   rL   b  s   rL   c                 C   s.   t ot| tj}t| tot| tj o| S N)r   r   __builtin__filer   ioIOBase)r   is_filer   r   r   is_iteratorf  s   rg   c                 C   s&   zt | jdkW S  ty   Y dS w )NcollectionsF)r%   rS   	Exceptionr   r   r   r   is_collectionsm  s
   rj   c                 C   s   t | do
t| jtS )Nr   )r   r$   r   rK   r   r   r   r   is_reducible_sequence_subclasst  s   rk   c                 C   s   t | rt| tjsdS t| tv rdS | tu rdS t| r dS t| tj	r(dS t
| r.dS t| r4dS tt| ddtr?dS t| rJ| jdkrJdS dS )zu
    Returns false if of a type which have special casing,
    and should not have their __reduce__ methods used
    TF	__slots__Ndatetime)rj   r   rh   defaultdictr%   NON_REDUCIBLE_TYPESr.   rL   r   rV   rJ   rk   r   r
   r   rS   r   r   r   r   is_reduciblex  s&   rp   Fc                 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   rr   r   keydefaultr   r   r   in_dict     rv   c                 C   rq   )zv
    Returns true if key exists in obj.__slots__; false if not in.
    If obj.__slots__ is absent, return default
    rl   N)r   rl   rs   r   r   r   in_slots  rw   rx   c                 C   s   t | rt| r
dS t| rdS d}d}d}d}t| |p!t| |}t| |p+t| |}t| jD ]}t |rE|p=t||}|pDt||}|rO|rO||f  S q1t| }tt|}tt|}|slt||d}	|	|url|	}|szt||d}
|
|urz|
}||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__)	rp   r   rP   rv   rx   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_clsr   r   r   r|     s:   

r|   c                 C      t ddd}|| | 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rb   
exceptionsr:   r!   r]   lookupr   r   r   translate_module_name  s   r   c                 C   s&   t | } trtddni }|| | 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.

    rb   )r   )_0_9_6_compat_untranslater   r:   r!   r   r   r   r   untranslate_module_name  s   r   c                 C   r   )zProvide compatibility for pickles created with jsonpickle 0.9.6 and
    earlier, remapping `exceptions` and `__builtin__` to `builtins`.
    r   r   r   r   r   r   r   r     s   r   c                 C   s$   t | d| j}t| 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__z{}.{})r   rT   r   rS   format)r   r&   r]   r   r   r   importable_name   s   
r   c                 C   s   t | dS )zI
    Encode binary data to ascii text in base64. Data must be bytes.
    ascii)base64	b64encodedecodedatar   r   r   r     s   r   c                 C   s
   t | S ).
    Decode payload - must be ascii text.
    )r   	b64decodepayloadr   r   r   r     s   
r   c                 C   s   t rtdt| dS )zI
    Encode binary data to ascii text in base85. Data must be bytes.
    z%Python 2 can't encode data in base85.r   )r   NotImplementedErrorr   	b85encoder   r   r   r   r   r   &  s   r   c                 C   s   t rtdt| S )r   z*Python 2 can't decode base85-encoded data.)r   r   r   	b85decoder   r   r   r   r   /  s   
r   c                 C   s   t || S ra   )r   rF   )r   getterr   r   r   
itemgetter8  s   r   c                 c   sN    t r|  D ]	\}}||fV  qdS t|  tdD ]	\}}||fV  qdS )a   Iterate over dicts in a deterministic order

    Python2 does not guarantee dict ordering, so this function
    papers over the difference in behavior.  Python3 does guarantee
    dict order, without use of OrderedDict, so no sorting is needed there.

    )rt   N)r   itemssortedr   )r   kvr   r   r   r   <  s   r   )F)S__doc__
__future__r   r   r   r   rh   rd   operatorr5   rN   r   r    r   r   r   r	   r
   r   r   r   r   rb   r?   rB   rH   rK   r=   rF   boolr%   r2   r   r   
LambdaTyper/   r   rQ   intfloatr:   r.   rD   ro   r   r-   r0   r3   r8   r;   r>   r@   rC   rE   rG   rI   rJ   rM   rP   rR   rU   rW   rZ   r^   rL   rg   rj   rk   rp   rv   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   $


	
0

				

5		