
    xKg                     l   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mZ ddlm	Z	 d Z
i Zd Zd Zd Zej                  Z G d	 d
      Zd Zd Z ej
                  ee       d Zd Zd Zd Zd Z G d dej0                        Zd Zeej6                  e<    G d dej8                        Z G d d      Zy)z/
Serialization support for compiled functions.
    N)cloudpickle)irc                       | j                   | S )zM
    Global hook to rebuild a given class from its __reduce__ arguments.
    )_rebuild)clsargss     X/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/core/serialize.py_rebuild_reductionr
      s     3<<    c                 ~    | |f}	 t         |   }|S # t        $ r" t        j                  |      xt         |<   }Y |S w xY w)zUsed by `numba_unpickle` from _helperlib.c

    Parameters
    ----------
    address : int
    bytedata : bytes
    hashed : bytes

    Returns
    -------
    obj : object
        unpickled object
    )_unpickled_memoKeyErrorr   loads)addressbytedatahashedkeyobjs        r	   _numba_unpickler      sW     F
CAc" J  A%0%6%6x%@@sJAs   	 '<<c                     t         }t        j                         5 } ||d      }|j                  |        |j	                         }ddd       |S # 1 sw Y   S xY w)zISimilar to `pickle.dumps()`. Returns the serialized object in bytes.
       )protocolN)NumbaPicklerioBytesIOdumpgetvalue)r   picklerbufppickleds        r	   dumpsr"   4   sO     G	C!$	s,,. 

 N 

 Ns   ,AAc                    t        j                  |       \  }}}g }t        |      }|D ]H  }t        |t        j
                        r|j                  t        |             8|j                  |       J |t        |      |fS N)	r   r   iter
isinstancer   Valueappendnexttuple)
static_excexc_argsexcstatic_argslocinfo	real_argsexc_args_iterargs           r	   runtime_build_excinfo_structr3   @   st     + 1 1* =CgINMc288$T-01S!	 
 y!7++r   c                   0    e Zd ZdZdZd Zd Zed        Zy)_CustomPickleda  A wrapper for objects that must be pickled with `NumbaPickler`.

    Standard `pickle` will pick up the implementation registered via `copyreg`.
    This will spawn a `NumbaPickler` instance to serialize the data.

    `NumbaPickler` overrides the handling of this type so as not to spawn a
    new pickler for the object when it is already being pickled by a
    `NumbaPickler`.
    ctorstatesc                      || _         || _        y r$   r6   )selfr7   r8   s      r	   __init__z_CustomPickled.__init__]   s    	r   c                 R    t         j                  | j                  | j                  ffS r$   )r5   r   r7   r8   r:   s    r	   _reducez_CustomPickled._reducea   s     &&DKK(@@@r   c                      | ||      S r$    )r   r7   r8   s      r	   r   z_CustomPickled._rebuildd   s    4  r   N)	__name__
__module____qualname____doc__	__slots__r;   r>   classmethodr   r@   r   r	   r5   r5   P   s-     !IA ! !r   r5   c                 6    t        |       \  }}t        ||      S )zPstandard unpickling for `_CustomPickled`.

    Uses `NumbaPickler` to load.
    )r   r5   )
serializedr7   r8   s      r	   _unpickle__CustomPickledrI   i   s    
 $LD&$''r   c                 V    t        | j                  | j                  f      }t        |ffS )zNstandard pickling for `_CustomPickled`.

    Uses `NumbaPickler` to dump.
    )r"   r7   r8   rI   )cprH   s     r	   _pickle__CustomPickledrL   r   s(    
 +,J#j]22r   c                 (    t         t        | |      ffS )a  For customizing object serialization in `__reduce__`.

    Object states provided here are used as keyword arguments to the
    `._rebuild()` class method.

    Parameters
    ----------
    states : dict
        Dictionary of object states to be serialized.

    Returns
    -------
    result : tuple
        This tuple conforms to the return type requirement for `__reduce__`.
    )custom_rebuildr5   )r   r8   s     r	   custom_reducerO      s      N37999r   c                 V    | j                   | j                  }} |j                  di |S )ziCustomized object deserialization.

    This function is referenced internally by `custom_reduce()`.
    r@   )r7   r8   r   )custom_pickledr   r8   s      r	   rN   rN      s-    
 !%%~'<'<C3<<!&!!r   c                     t        j                         5 }t        |      }	 |j                  |        	 ddd       y# t        j
                  $ r Y ddd       yw xY w# 1 sw Y   yxY w)zCheck if *obj* can be serialized.

    Parameters
    ----------
    obj : object

    Returns
    --------
    can_serialize : bool
    NTF)r   r   r   r   picklePicklingError)r   foutr   s      r	   is_serialiablerV      s_     
t$	LL  
 ## 	 
		 
s+   A=AAAAAA'c                 F    t        j                  dt        |        d      )NzPickling of z is unsupported)rS   rT   type)r   s    r	   
_no_picklerY      s     


d3i[H
IIr   c                 D    t         j                  j                  |        | S )z1This is called on a type to disable pickling
    )r   disabled_typesadd)typs    r	   disable_picklingr^      s     ##C(Jr   c                   .     e Zd Z e       Z	  fdZ xZS )r   c                 f    t        |      | j                  v rt        |       t        |   |      S r$   )rX   r[   rY   superreducer_override)r:   r   	__class__s     r	   rb   zNumbaPickler.reducer_override   s,    9+++sOw',,r   )rA   rB   rC   setr[   rb   __classcell__rc   s   @r	   r   r      s    UN- -r   r   c                 "    | j                         S r$   )r>   )rK   s    r	   _custom_reduce__custompickledrh      s    ::<r   c                   d    e Zd ZdZej
                  d        Zej                  d        Zd Z	d Z
y)ReduceMixinznA mixin class for objects that should be reduced by the NumbaPickler
    instead of the standard pickler.
    c                     t         r$   NotImplementedErrorr=   s    r	   _reduce_stateszReduceMixin._reduce_states       !!r   c                     t         r$   rl   )r   kwargss     r	   r   zReduceMixin._rebuild   ro   r   c                     | j                   S r$   rf   r=   s    r	   _reduce_classzReduceMixin._reduce_class   s    ~~r   c                 R    t        | j                         | j                               S r$   )rO   rs   rn   r=   s    r	   
__reduce__zReduceMixin.__reduce__   s!    T//143F3F3HIIr   N)rA   rB   rC   rD   abcabstractmethodrn   abstractclassmethodr   rs   ru   r@   r   r	   rj   rj      sF    
 	" " 	" "

Jr   rj   c                   2    e Zd ZdZd Zd Zd Zed        Zy)PickleCallableByPatha  Wrap a callable object to be pickled by path to workaround limitation
    in pickling due to non-pickleable objects in function non-locals.

    Note:
    - Do not use this as a decorator.
    - Wrapped object must be a global that exist in its parent module and it
      can be imported by `from the_module import the_object`.

    Usage:

    >>> def my_fn(x):
    >>>     ...
    >>> wrapped_fn = PickleCallableByPath(my_fn)
    >>> # refer to `wrapped_fn` instead of `my_fn`
    c                     || _         y r$   _fn)r:   fns     r	   r;   zPickleCallableByPath.__init__   s	    r   c                 &     | j                   |i |S r$   r|   )r:   r   rq   s      r	   __call__zPickleCallableByPath.__call__   s    txx(((r   c                     t        |       j                  | j                  j                  | j                  j                  ffS r$   )rX   r   r}   rB   rA   r=   s    r	   ru   zPickleCallableByPath.__reduce__   s0    Dz""TXX%8%8$((:K:K$MMMr   c                 H     | t        t        j                  |   |            S r$   )getattrsysmodules)r   modnamefn_paths      r	   r   zPickleCallableByPath._rebuild  s    73;;w/9::r   N)	rA   rB   rC   rD   r;   r   ru   rF   r   r@   r   r	   rz   rz      s+    )N ; ;r   rz   )rD   r   rv   r   copyregrS   numbar   llvmliter   r
   r   r   r"   r3   r   r5   rI   rL   rO   rN   rV   rY   r^   CloudPicklerr   rh   dispatch_tableABCrj   rz   r@   r   r	   <module>r      s     
 	     ,		, 	! !2(3 ~5 6:&"*J	-;++ 	- /L  N +J#'' J2; ;r   