
    Ǆgp                        d Z ddlZddl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
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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ZddlmZ ej8                  Z e       Z ej@                         Z! ejD                         Z# ejH                         Z% ejL                         Z' ejP                         dk(  Z)dZ*e)r e+e,jZ                  j\                        Z* ej@                         Z/d Z0d	 Z1d
 Z2d Z3d Z4d Z5d Z6dOdZ7dOdZ8d Z9d Z:ejv                  d   Z<ejv                  d   Z=ejv                  d   Z>e<e=e>fZ?e	j                  Z@e	j                  ZAi ZBej                  j                         D ]  \  ZEZF e+eF      e+u seEeBeF<    d ZGd ZHd ZId ZJd ZKd ZLd ZMd ZNeN G d d             ZOd  ZPd! ZQeOfd"ZRd# ZSd$ ZTd% ZUd& ZVd' ZWd( ZXdPd)ZYdPd*ZZdPd+Z[d, Z\d- Z]d. Z^d/ Z_d0 Z`d1 Zad2 Zbd3 Zcd4 Zdd5 Zed6 Zfd7 Zgd8 Zhd9 Zid: Zjd; Zkd< Zld= Zmd> Znd? Zod@ ZpdA ZqdB ZrdC ZsdD ZtdE ZudF ZvdG ZwdH ZxdI Zyej                  j                  ej                  ej                  j                  ej                  ej                  j                  ej                  iZ~dJ Z G dK dLej                         ZdQdMZdQdNZej                  ej                  cZZeZy)Ra  
This is a modified version of the cloudpickle module.
Patches:
- https://github.com/numba/numba/pull/7388
  Avoid resetting class state of dynamic classes.

Original module docstring:

Pickler class to extend the standard pickle.Pickler functionality

The main objective is to make it natural to perform distributed computing on
clusters (such as PySpark, Dask, Ray...) with interactively defined code
(functions, classes, ...) written in notebooks or console.

In particular this pickler adds the following features:
- serialize interactively-defined or locally-defined functions, classes,
  enums, typevars, lambdas and nested functions to compiled byte code;
- deal with some other non-serializable objects in an ad-hoc manner where
  applicable.

This pickler is therefore meant to be used for the communication between short
lived Python processes running the same version of Python and libraries. In
particular, it is not meant to be used for long term storage of Python objects.

It does not include an unpickler, as standard Python unpickling suffices.

This module was extracted from the `cloud` package, developed by `PiCloud, Inc.
<https://web.archive.org/web/20140626004012/http://www.picloud.com/>`_.

Copyright (c) 2012-now, CloudPickle developers and contributors.
Copyright (c) 2012, Regents of the University of California.
Copyright (c) 2009 `PiCloud, Inc. <https://web.archive.org/web/20140626004012/http://www.picloud.com/>`_.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the University of California, Berkeley nor the
      names of its contributors may be used to endorse or promote
      products derived from this software without specific prior written
      permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    N)ChainMapOrderedDict)Enum)_getattribute)CellTypePyPyc                     t         5  t        j                  |       }|0t        j                         j
                  }|t        | <   | t        |<   d d d        |S # 1 sw Y   S xY wN)_DYNAMIC_CLASS_TRACKER_LOCK_DYNAMIC_CLASS_TRACKER_BY_CLASSgetuuiduuid4hex_DYNAMIC_CLASS_TRACKER_BY_ID)	class_defclass_tracker_ids     e/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/numba/cloudpickle/cloudpickle.py_get_or_create_tracker_idr   u   sh    	$ G:>>yI##zz|//9I+I6=F()9:G G s   AAA#c                     | Kt         5  |}t        j                  | |      }| t        |<   ||urt        j                  |       d d d        |S |S # 1 sw Y   |S xY wr
   )r   r   
setdefaultr   _DYNAMIC_CLASS_TRACKER_REUSINGadd)r   r   orig_class_defs      r   _lookup_class_or_trackr      sn    #( 		>&N4?? )I :J+I6Y..229=		> 9		> s   ;AAc                     t        | t        j                        st        dt	        |        d      | j
                  t        j                  vrt        |  d      t        j                  | j
                         y)a  Register a module to make it functions and classes picklable by value.

    By default, functions and classes that are attributes of an importable
    module are to be pickled by reference, that is relying on re-importing
    the attribute from the module at load time.

    If `register_pickle_by_value(module)` is called, all its functions and
    classes are subsequently to be pickled by value, meaning that they can
    be loaded in Python processes where the module is not importable.

    This is especially useful when developing a module in a distributed
    execution environment: restarting the client Python process with the new
    source code is enough: there is no need to re-install the new version
    of the module on all the worker nodes nor to restart the workers.

    Note: this feature is considered experimental. See the cloudpickle
    README.md file for more details and limitations.
    %Input should be a module object, got  insteadzN was not imported correctly, have you used an `import` statement to access it?N)

isinstancetypes
ModuleType
ValueErrorstr__name__sysmodules_PICKLE_BY_VALUE_MODULESr   modules    r   register_pickle_by_valuer*      so    & fe../@VXVWW ckk)h / /
 	
   1    c                     t        | t        j                        st        dt	        |        d      | j
                  t        vrt        |  d      t        j                  | j
                         y)z<Unregister that the input module should be pickled by value.r   r   z& is not registered for pickle by valueN)r   r    r!   r"   r#   r$   r'   remover(   s    r   unregister_pickle_by_valuer.      s]    fe../@VXVWW66F8#IJKK ''8r+   c                  *    t         j                         S r
   )r'   copy r+   r   list_registry_pickle_by_valuer2      s    #((**r+   c                 ~    | j                   }|t        v ry	 |j                  dd      d   }||k(  r	 y|t        v ry|}()NT.   r   F)r$   r'   rsplit)r)   module_nameparent_names      r   _is_registered_pickle_by_valuer9      sY    //K..
!((a03+%  22! r+   c                    t        | dd      }||S t        j                  j                         j	                         D ]=  \  }}|dk(  s|t        |t        j                        s(	 t        ||      d   | u r|c S ? y# t        $ r Y Lw xY w)aU  Find the module an object belongs to.

    This function differs from ``pickle.whichmodule`` in two ways:
    - it does not mangle the cases where obj's module is __main__ and obj was
      not found in any module.
    - Errors arising during module introspection are ignored, as those errors
      are considered unwanted side effects.
    
__module__N__main__r   )
getattrr%   r&   r0   itemsr   r    r!   r   	Exception)objnamer7   r)   s       r   _whichmodulerB      s     #|T2K  #{{//1779 V :%~fe&6&67	VT*1-4"" 5   		s   'A??	B
Bc                    t        | t        j                        st        t	        |       t              r!t        | |      }|y|\  }}t        |       S t        | t        j                        r(t        |       ry| j                  t        j                  v S t        dj                  t	        |       j                              )a  Test whether an function or a class should be pickled by reference

    Pickling by reference means by that the object (typically a function or a
    class) is an attribute of a module that is assumed to be importable in the
    target Python environment. Loading will therefore rely on importing the
    module and then calling `getattr` on it to access the function or class.

    Pickling by reference is the only option to pickle functions and classes
    in the standard library. In cloudpickle the alternative option is to
    pickle by value (for instance for interactively or locally defined
    functions and classes or for attributes of modules that have been
    explicitly registered to be pickled by value.
    rA   Fz*cannot check importability of {} instances)r   r    FunctionType
issubclasstype_lookup_module_and_qualnamer9   r!   r$   r%   r&   	TypeErrorformat)r@   rA   module_and_namer)   s       r   _should_pickle_by_referencerL      s     #u))*jcD.I5cE"&1&999	C))	* *#.||s{{**8??S	@R@RS
 	
r+   c                     |t        | dd       }|t        | dd       }t        | |      }|y |dk(  ry t        j                  j	                  |d       }|y 	 t        ||      \  }}|| ury ||fS # t        $ r Y y w xY w)N__qualname__r$   r<   )r=   rB   r%   r&   r   r   AttributeError)r@   rA   r7   r)   obj2parents         r   rH   rH     s    |sND1| sJ-sD)K j  [[__[$/F~ $VT2f 34<  s   A0 0	A<;A<c                 &   t         j                  |       }|tt        |       D ci c]  }|d }}| j                  rF| j                  D ]7  }t	        |t
        j                        s|j                  t        |             9 |t         | <   |S c c}w )z:Find all globals names read or written to by codeblock co.N)	_extract_code_globals_cacher   _walk_global_ops	co_constsr   r    CodeTypeupdate_extract_code_globals)co	out_namesrA   consts       r   rX   rX   >  s    +//3I -=R,@ADT4ZA	A << CeU^^4$$%:5%ABC +4#B' Bs   
Bc                    g }|D ]  }t        |t        j                        st        |d      s+|j                  s8|j
                  dz   }t        t        j                        D ]x  }||j                  |      st        |t        |      d j                  d            }|t        | j                        z
  rW|j                  t        j                  |          z  |S )a!  Find currently imported submodules used by a function.

    Submodules used by a function need to be detected and referenced for the
    function to work correctly at depickling time. Because submodules can be
    referenced as attribute of their parent package (``package.submodule``), we
    need a special introspection technique that does not rely on GLOBAL-related
    opcodes to find references of them in a code object.

    Example:
    ```
    import concurrent.futures
    import cloudpickle
    def func():
        x = concurrent.futures.ThreadPoolExecutor
    if __name__ == '__main__':
        cloudpickle.dumps(func)
    ```
    The globals extracted by cloudpickle in the function's state include the
    concurrent package, but not its submodule (here, concurrent.futures), which
    is the module used by func. Find_imported_submodules will detect the usage
    of concurrent.futures. Saving this module alongside with func will ensure
    that calling func once depickled does not fail due to concurrent.futures
    not being imported
    __package__r4   N)r   r    r!   hasattrr]   r$   listr%   r&   
startswithsetlensplitco_namesappend)codetop_level_dependencies
subimportsxprefixrA   tokenss          r   _find_imported_submodulesrl   W  s    4 J# =q%**+=) ZZ#%F S[[) = #(? c&km!4!:!:3!?@F!C$66"))#++d*;<==$ r+   STORE_GLOBALDELETE_GLOBALLOAD_GLOBALc                 8    | dk(  rt         S t        t        |       S )N	ClassType)rG   r=   r    rD   s    r   _builtin_typerr     s    { 5$r+   c              #      K   t        j                  |       D ]%  }|j                  }|t        v s|j                   ' yw)zBYield referenced name for global-referencing instructions in code.N)disget_instructionsopcode
GLOBAL_OPSargval)rf   instrops      r   rT   rT     s;     %%d+ \\,,s
   -AAc                    t        | j                        }t        | j                        dk(  r| j                  d   j                  }n7i }t	        | j                        D ]  }|j                  |j                          g }|j                         D ]   \  }}	 ||   }||u r|j                  |       " |D ]  }|j                  |        |S # t        $ r Y Hw xY w)zDRetrieve a copy of the dict of a class without the inherited method.r5   r   )
dict__dict__rb   	__bases__reversedrW   r>   re   KeyErrorpop)clsclsdictinherited_dictbase	to_removerA   value
base_values           r   _extract_class_dictr     s    3<< G
3==Qq)22S]]+ 	1D!!$--0	1I}} e	'-J
"  &	  DN	  		s   C	CCc                     t        j                  dt               dt        j                  vryt        j                  d   }t        |d      sy|j                  |       S )zfReturn whether `func` is a Tornado coroutine function.

    Running coroutines are not supported.
    zis_tornado_coroutine is deprecated in cloudpickle 3.0 and will be removed in cloudpickle 4.0. Use tornado.gen.is_coroutine_function directly instead.)categoryztornado.genFis_coroutine_function)warningswarnDeprecationWarningr%   r&   r^   r   )funcgens     r   is_tornado_coroutiner     sX    
 MM	 $	 CKK'
++m
$C3/0$$T**r+   c                 >    t        |        t        j                  |    S r
   )
__import__r%   r&   rD   s    r   	subimportr     s    
 t;;tr+   c                     t        j                  |       }|j                  j                  |       t        j                  |j                  d<   |S N__builtins__)r    r!   r}   rW   builtins)rA   varsmods      r   dynamic_subimportr     s=    


4
 CLL#+#4#4CLL Jr+   c                 F    	 | j                   S # t        $ r	 t        cY S w xY wr
   )cell_contentsr"   _empty_cell_valuecells    r   _get_cell_contentsr     s(    !!!! !  !s      c                      |        S )zCreate a new instance of a class.

    Parameters
    ----------
    cls : type
        The class to create an instance of.

    Returns
    -------
    instance : cls
        A new instance of ``cls``.
    r1   r   s    r   instancer     s     5Lr+   c                        e Zd ZdZed        Zy)r   zSentinel for empty closures.c                     | j                   S r
   )r$   r   s    r   
__reduce__z_empty_cell_value.__reduce__  s    ||r+   N)r$   r;   rN   __doc__classmethodr   r1   r+   r   r   r     s    & r+   r   c                 F    t         |d<   t        j                  | ||||      S r   )r   r    rE   )rf   globalsrA   argdefsclosures        r   _make_functionr     s%    *GNdGT7GDDr+   c                  *     	  fdj                  d   S )Nc                       S r
   r1   r   s   r   <lambda>z"_make_empty_cell.<locals>.<lambda>  s    D r+   r   )AssertionError__closure__r   s   @r   _make_empty_cellr   	  s    
 %%a((r+   c                 8    t               }| t        ur| |_        |S r
   )r   r   r   )r   r   s     r   
_make_cellr     s     D%%"Kr+   c                 V    t        j                  ||d| ifd      }t        ||      S )a  Build dynamic class with an empty __dict__ to be filled once memoized

    If class_tracker_id is not None, try to lookup an existing class definition
    matching that id. If none is found, track a newly reconstructed class
    definition under that id so that other instances stemming from the same
    class id will also reuse this class definition.

    The "extra" variable is meant to be a dict (or None) that can be used for
    forward compatibility shall the need arise.
    	metaclassc                 &    | j                        S r
   )rW   )nstype_kwargss    r   r   z&_make_skeleton_class.<locals>.<lambda>'  s    ;AW r+   )r    	new_classr   )type_constructorrA   basesr   r   extraskeleton_classs      `   r   _make_skeleton_classr     s3     __ek#346WN ""2NCCr+   c                     | d   }|j                   }|j                  ||       }	|j                         D ]
  \  }
}||	|
<    |j                  ||| |	      }||_        ||_        t        ||      S )a6  Build dynamic enum with an empty __dict__ to be filled once memoized

    The creation of the enum class is inspired by the code of
    EnumMeta._create_.

    If class_tracker_id is not None, try to lookup an existing enum definition
    matching that id. If none is found, track a newly reconstructed enum
    definition under that id so that other instances stemming from the same
    class id will also reuse this enum definition.

    The "extra" variable is meant to be a dict (or None) that can be used for
    forward compatibility shall the need arise.
    )	__class____prepare__r>   __new__r;   rN   r   )r   rA   qualnamemembersr)   r   r   	enum_basemetacls	classdictmember_namemember_value
enum_classs                r   _make_skeleton_enumr   ,  s    $ b	I!!G##D%0I%,]]_ .!\!-	+.$yAJ"J&J!"2J??r+   c                 P    t        j                  | g||||d}t        ||      S )N)bound	covariantcontravariant)typingTypeVarr   )rA   r   constraintsr   r   r   tvs          r   _make_typevarr   K  s;    	
	
 #
B ""2B77r+   c                     | j                   | j                  | j                  | j                  | j                  t        |       fS r
   )r$   	__bound____constraints____covariant____contravariant__r   r@   s    r   _decompose_typevarr   V  s=    !#& r+   c                     t        | | j                        }|t        t        |       fS t	        |d         rt        t        |       fS t
        |fS )NrD   r   )rH   r$   r   r   r9   r=   )r@   rK   s     r   _typevar_reducer   a  sT     2#CLLIO1#677	'(:	;1#677_%%r+   c                 B    dt        | di       v rd}nd}t        | |      S )N__orig_bases__r}   r~   )r=   )typ
bases_attrs     r   
_get_basesr   n  s.    73
B77 &
 !
3
##r+   c                     |r#t        j                  |       j                         S t        j                  |       j                         S r
   )r   fromkeyskeysr|   r@   
is_ordereds     r   _make_dict_keysr   |  s7    ##C(--//}}S!&&((r+   c                     |r)t        d t        |       D              j                         S t        |       D ci c]  \  }}||
 c}}j                         S c c}}w )Nc              3   *   K   | ]  \  }}||f  y wr
   r1   ).0i_s      r   	<genexpr>z$_make_dict_values.<locals>.<genexpr>  s     =daAq6=s   )r   	enumeratevalues)r@   r   r   r   s       r   _make_dict_valuesr     sL    =in==DDFF!*30A1077990s   Ac                 X    |rt        |       j                         S | j                         S r
   )r   r>   r   s     r   _make_dict_itemsr     s%    3%%''yy{r+   c                     i }d| j                   v r| j                  |d<   | j                   j                  dd       }t        |t              r||d<   t        |       | j                  t        |       |t        |       d fS )Nr;   r}   )	r}   r;   r   r   propertyrG   r$   r   r   )r@   r   r}   s      r   _class_getnewargsr     sz    Ks||#$'NNL!||
D1H(H%"*J 	S	3!#& r+   c                     | D ci c]  }|j                   |j                   }}| j                  | j                  | j                  || j
                  t        |       d fS c c}w r
   )rA   r   r~   r$   rN   r;   r   )r@   er   s      r   _enum_getnewargsr     s\    (+,1qvvqww,G,!#&  -s   Ac                     | S r
   r1   )retvals    r   _file_reconstructorr    s    Mr+   c           	      H   | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  d}t        | j                        }|D ci c]!  }|| j                  v s|| j                  |   # }}| j                  $t        t        t        | j                              }nd}t        | j                  t        j                   |j#                         |            |d<   ||d<   | j$                  }||fS c c}w )N)r$   rN   __annotations____kwdefaults____defaults__r;   r   r   r1   _cloudpickle_submodules__globals__)r$   rN   r  r  r  r;   r   r   rX   __code__r  r_   mapr   rl   	itertoolschainr   r}   )r   	slotstatef_globals_refk	f_globalsclosure_valuesstates          r   _function_getstater    s    MM))//--))oo<<''	I *$--8M1>XA!tGWGWBWD$$Q''XIX#c"4d6F6FGH ,Eyy'7'7'9>J,I'(  )ImMME)# Ys   5D	Dc                    t        |       }|j                  dd        t        t        |       t        j
                        r|j                  dd        |j                  dd        |j                  dd        |j                  dd       }|E|j                  dd        t	        j                  |       \  }}}}|D cg c]	  } |        c}|d<   n|D cg c]  }| c}|d<   d|v rYt        | j                  t              r|j                  | j                         n#| j                  D ]  }|j                  |d         |j                  dd        |i fS c c}w c c}w )	N__weakref__
_abc_cache_abc_negative_cache_abc_negative_cache_version_abc_registry	_abc_impl	__slots__r}   )
r   r   rF   rG   abcABCMeta	_get_dumpr   r  r#   )r@   r   registryr   subclass_weakreftype_r  s          r   _class_getstater!    s8   !#&GKKt$$s)S[[) 	L$')40148;;5 KKT*"%--"4Xq!QOW#X;K$4$6#XGK  8@#@eE#@GK g cmmS)KK&]] %At$% KK
D!R=% $Y $As   ;E	Ec                     t        |       \  }}| D ci c]  }|j                  |j                   }}dD ]  }|j                  |d         |D ]  }|j                  |        ||fS c c}w )N)_generate_next_value__member_names__member_map__member_type__value2member_map_)r!  rA   r   r   )r@   r   r  r   r   attrnamemembers          r   _enum_getstater*    s    (-GY(+,1qvvqww,G, $ 	Hd#$  F I -s   A(c                    t        | d      r| j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  | j$                  f}nht        | d      r| j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j"                  | j$                  f}nt        | d      r| j                  | j                  | j                  | j                  | j&                  | j(                  | j*                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j,                  | j.                  | j0                  | j"                  | j$                  | j2                  | j4                  f}n| j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j,                  | j"                  | j$                  f}t6        j8                  |fS )zcode object reducer.co_exceptiontableco_linetableco_nmeta)r^   co_argcountco_posonlyargcountco_kwonlyargcount
co_nlocalsco_stacksizeco_flagsco_coderU   rd   co_varnamesco_filenameco_nameco_qualnameco_firstlinenor-  r,  co_freevarsco_cellvarsco_framesizeco_ndefaultargsr.  	co_lnotabco_exc_handlersco_jump_tableco_free2regco_cell2regr    rV   )r@   argss     r   _code_reducerE  -  sy    s'( OO""!!NNLLKKMMLLOOOOKKOO!!OOOO%
( 
n	% OO""!!NNLLKKMMLLOOOOKKOOOO!
$ 
j	! OO""!!NNLLLLKKMMOOOOKKMMOOOOOOOO+
4 OO""!!NNLLKKMMLLOOOOKKMMOOOO!
$ >>4r+   c                 p    	 | j                    t        | j                   ffS # t        $ r t        dfcY S w xY w)z@Cell (containing values of a function's free variables) reducer.r1   )r   r   r"   r   r   s    r   _cell_reducerG    sB    0 C--///  $##$s   ! 55c                 6    | j                   }t        |       |ffS r
   )__func__rG   )r@   	orig_funcs     r   _classmethod_reducerK    s    I9yl""r+   c                    ddl }t        | d      rt        | d      st        j                  d      | t        j
                  u rt        t        dffS | t        j                  u rt        t        dffS | t        j                  u rt        j                  d      | j                  rt        j                  d	      t        | d
      r%| j                         rt        j                  d      d| j                  vr0d| j                  vr"t        j                  d| j                  z        | j                  } |j                         }	 | j                         }| j                  d       | j!                         }| j                  |       |j%                  |       |j                  |       ||_        t&        |ffS # t"        $ r}t        j                  d|z        |d}~ww xY w)zSave a file.r   NrA   modez5Cannot pickle files that do not map to an actual filestdoutstderrzCannot pickle standard inputzCannot pickle closed filesisattyz+Cannot pickle files that map to tty objectsr+z7Cannot pickle files that are not opened for reading: %sz*Cannot pickle file %s as it cannot be read)ior^   picklePicklingErrorr%   rN  r=   rO  stdinclosedrP  rM  rA   StringIOtellseekreadOSErrorwriter  )r@   rS  rA   r   curloccontentsr   s          r   _file_reducer`    s   3wsF';""C
 	
 cjjh''
cjjh''
cii""#ABB
zz""#?@@sH#**,""#PQQ
#((s#((2""EP
 	
 88DR[[]F	88:
 LL
KKFK	))  ""84?
	s   AF; ;	G"GG"c                 >    t         | j                  | j                  ffS r
   )r=   __objclass__r$   r   s    r   _getset_descriptor_reducerc    s    S%%s||444r+   c                 :    t         j                  t        |       ffS r
   )r    MappingProxyTyper|   r   s    r   _mappingproxy_reducerf    s    !!DI<//r+   c                 0    t         | j                         ffS r
   )bytestobytesr   s    r   _memoryview_reducerj    s    3;;="""r+   c                     t        |       rt        | j                  ffS | j                  j	                         }|j                  dd        t        | j                  |ffS r   )rL   r   r$   r}   r0   r   r   )r@   r  s     r   _module_reducerl    sQ    "3'3<</)) !!#		.$' 3<<"777r+   c                 R    t         j                  | j                  | j                  ffS r
   )r    
MethodTyperI  __self__r   s    r   _method_reducerp    s     s||S\\:;;r+   c                 <    t         j                  | j                  ffS r
   )logging	getLoggerrA   r   s    r   _logger_reducert    s    sxxk))r+   c                 &    t         j                  dfS )Nr1   )rr  rs  r   s    r   _root_logger_reducerv    s    b  r+   c                 j    t         | j                  | j                  | j                  | j                  ffS r
   )r   fgetfsetfdelr   r   s    r   _property_reducer{    s&    chh#((CKK@@@r+   c                 :    t         j                  t        |       ffS r
   )weakrefWeakSetr_   r   s    r   _weakset_reducer    s    ??T#YL((r+   c                     t         2t        | t               r"t        t        |       t	        |       ddt
        fS t        t        |       t        |       ddt
        fS )zSave a class that can't be referenced as a module attribute.

    This method is used to serialize classes that are defined inside
    functions, or that otherwise can't be serialized as attribute lookups
    from importable modules.
    N)	r   rF   r   r   r*  _class_setstater   r   r!  r   s    r   _dynamic_class_reducer    sa     JsD1S!3
 	
 !c"C 
 	
r+   c                    | t        d      u rt         dfS | t        t              u rt         t        ffS | t        t              u rt         t        ffS | t        v rt        t        |    ffS t        |       st        |       S t        S )zDSelect the reducer depending on the dynamic nature of the class obj.Nr
   )rG   EllipsisNotImplemented_BUILTIN_TYPE_NAMESrr   rL   r  r   s    r   _class_reducer    s    
d4jW}	X	h[  	^$	$n&&&	#	#237999(-$S))r+   c                 &    t         t        |       ffS r
   r   r_   r   s    r   _dict_keys_reducer  !  s     T#YL((r+   c                 &    t         t        |       ffS r
   r   r_   r   s    r   _dict_values_reducer  (  s     tCyl**r+   c                 &    t         t        |       ffS r
   r   r|   r   s    r   _dict_items_reducer  /  s    d3i\))r+   c                 (    t         t        |       dffS NTr  r   s    r   _odict_keys_reducer  3  s     T#Y---r+   c                 (    t         t        |       dffS r  r  r   s    r   _odict_values_reducer  :  s     tCy$///r+   c                 (    t         t        |       dffS r  r  r   s    r   _odict_items_reducer  A  s    d3i...r+   c                 (    t         | j                  ffS r
   )"_get_dataclass_field_type_sentinelrA   r   s    r   _dataclass_field_base_reducer  E  s    -{::r+   c                    |\  }}| j                   j                  |       |j                  d      }|j                  d      }|j                  d       | j                  j                  |       t        | j                  d<   |4t        |      D ]&  \  }}	 |j                  }|| j                  |   _        ( |j                         D ]  \  }}	t        | ||	        y# t        $ r Y Zw xY w)a  Update the state of a dynamic function.

    As __closure__ and __globals__ are readonly attributes of a function, we
    cannot rely on the native setstate routine of pickle.load_build, that calls
    setattr on items of the slotstate. Instead, we have to modify them inplace.
    r  r   r  r   N)r}   rW   r   r  r   r   r   r"   r   r>   setattr)
r@   r  r  obj_globalsobj_closurer   r   r   r  vs
             r   _function_setstater  O  s     E9LL--.K--.K MM+,OO;'&2COON# - 	5GAt** 05COOA,	5 ! 1Q	  s   C	C*)C*c                     | t         v r| S |\  }}d }|j                         D ]  \  }}|dk(  r|}t        | ||        ||D ]  }| j                  |        | S )Nr  )r   r>   r  register)r@   r  r  r  r(  attrsubclasss          r   r  r  q  s{    
,,
E9H++- )${"HC4(	)
   	#HLL"	# Jr+   c                     t         |    S r
   ) _DATACLASSE_FIELD_TYPE_SENTINELSrD   s    r   r  r    s    +D11r+   c                   6    e Zd Zi Zeee<   eeej                  <   e	ee
j                  <   eee
j                  <   eee<   eee<   eee<   eee<   eeej.                  <   eeej2                  <   eeej6                  <   eeej:                  <   eeej>                  <   e ee!jD                  <   e#ee$jJ                  <   e&ee'jP                  <   e)ee'jT                  <   e+ee'jX                  <   e-e e. e/       ja                               <   e1e e. e/       je                               <   e3e e. e/       ji                               <   eee5jl                  <   eee5jn                  <   eee5jp                  <   eee5jr                  <   e:ee;jx                  <    e=ee>j~                        Z?d Z@d ZAd ZB fdZCd fd	ZDeEs	e?ZFd ZG xZRS eHj                  j                  j                         ZF	 	 	 	 	 ddZKdeLj                  f fd		ZNeNeFe.<   d fd
	ZOd ZPeOeFej                  <    xZRS )Picklerc                 Z    | j                  |      }t        |      }t        ||ddt        fS )z>Reduce a function that is not pickleable via attribute lookup.N)_function_getnewargsr  r   r  )selfr   newargsr  s       r   _dynamic_function_reducez Pickler._dynamic_function_reduce  s0    ++D1"4(d<NOOr+   c                 F    t        |      rt        S | j                  |      S )az  Reducer for function objects.

        If obj is a top-level attribute of a file-backed module, this reducer
        returns NotImplemented, making the cloudpickle.Pickler fall back to
        traditional pickle.Pickler routines to save obj. Otherwise, it reduces
        obj using a custom cloudpickle reducer designed specifically to handle
        dynamic functions.
        )rL   r  r  )r  r@   s     r   _function_reducezPickler._function_reduce  s#     's+!!0055r+   c                 Z   |j                   }| j                  j                  t        |j                        i       }|i k(  r(dD ]#  }||j                  v s|j                  |   ||<   % |j
                  d }n.t        d t        t        |j                              D              }||d d |fS )N)r]   r$   __path____file__c              3   0   K   | ]  }t                 y wr
   )r   )r   r   s     r   r   z/Pickler._function_getnewargs.<locals>.<genexpr>  s     U1,.Us   )
r  globals_refr   idr  r   tuplerangerb   r;  )r  r   rf   base_globalsr  r   s         r   r  zPickler._function_getnewargs  s    }} ''222d6F6F3GL2 I :(((&*&6&6q&9LO: #GUc$BRBR>S8TUUG\4w66r+   c                     	 t         |   |      S # t        $ rG}t        |j                        dkD  r)d|j                  d   v rd}t        j                  |      | d }~ww xY w)Nr   	recursionz?Could not pickle object as excessively deep recursion required.)superdumpRuntimeErrorrb   rD  rT  rU  )r  r@   r   msgr   s       r   r  zPickler.dump  s`    	7<$$ 	166{Q;!&&)#;W**3/Q6	s    	A"AAA"Nc                 h    |t         }t        | 	  |||       i | _        t	        |      | _        y )Nprotocolbuffer_callback)DEFAULT_PROTOCOLr  __init__r  intproto)r  filer  r  r   s       r   r  zPickler.__init__  s7    'H/R ]
r+   c                     t        |      }	 t        |t               }|rt        |      S t	        |t
        j                        r| j                  |      S t        S # t        $ r d}Y Kw xY w)a=  Type-agnostic reducing callback for function and classes.

            For performance reasons, subclasses of the C `pickle.Pickler` class
            cannot register custom reducers for functions and classes in the
            dispatch_table attribute. Reducers for such types must instead
            implemented via the special `reducer_override` method.

            Note that this method will be called for any object except a few
            builtin-types (int, lists, dicts etc.), which differs from reducers
            in the Pickler's dispatch_table, each of them being invoked for
            objects of a specific type only.

            This property comes in handy for classes: although most classes are
            instances of the ``type`` metaclass, some of them can be instances
            of other custom metaclasses (such as enum.EnumMeta for example). In
            particular, the metaclass will likely not be known in advance, and
            thus cannot be special-cased using an entry in the dispatch_table.
            reducer_override, among other things, allows us to register a
            reducer that will be called for any class, independently of its
            type.

            Notes:

            * reducer_override has the priority over dispatch_table-registered
            reducers.
            * reducer_override can be used to fix other limitations of
              cloudpickle for other types that suffered from type-specific
              reducers, such as Exceptions. See
              https://github.com/cloudpipe/cloudpickle/issues/248
            F)	rG   rF   rI   r  r   r    rE   r  r  )r  r@   tis_anyclasss       r   reducer_overridezPickler.reducer_override  sm    > S	A$(D1 $S))C!3!34,,S11 &%  $#$s   A A)(A)c                    | j                   }| j                  }	| j                  ||d |||        ||        ||        ||        |	t        j                          |	t        j
                          |	t        j                         y )N)r  	listitems	dictitemsr@   )saver]  save_reducerT  TUPLE2REDUCEPOP)
r  r   rD  r  r  r  state_setterr@   r  r]  s
             r   _save_reduce_pickle5zPickler._save_reduce_pickle5P  sy     99DJJE##   IK&-- &-- 
 &**r+   c                    |t        d      u r| j                  t         d|      S |t        t              u r| j                  t         t        f|      S |t        t              u r| j                  t         t        f|      S |t        v r | j                  t
        t        |   f|      S |t        |   ||       yt        ||      s | j                  t        |      d|i yt        |   ||       y)zMain dispatch method.

            The name of this method is somewhat misleading: all types get
            dispatched here.
            Nr
   r   rD   r@   )rG   r  r  r  r  rr   r  save_globalrL   r  r  )r  r@   rA   packr   s       r   r  zPickler.save_globalq  s     d4j ''g3'??X&''xks'CC^,,''~.?S'II++''!$7$<#>C (   #Cd#304@)))+@+EO3O#Cd#3r+   c                     t        ||      rt        | 	  ||      S t        r+t	        |j
                  t              r| j                  |      S  | j                  | j                  |      d|iS )zRegistered with the dispatch to handle all function types.

            Determines what kind of function obj is (e.g. lambda, defined at
            interactive prompt, etc) and handles the pickling appropriately.
            rD   r@   )
rL   r  r  PYPYr   r  builtin_code_typesave_pypy_builtin_funcr  r  )r  r@   rA   r   s      r   save_functionzPickler.save_function  sq     +3T:w*3T*::*S\\3DE223770t002237=@ r+   c                     t         j                  |j                  i |j                  |j                  |j
                  f|j                  f} | j                  |d|i y)a  Save pypy equivalent of builtin functions.

            PyPy does not have the concept of builtin-functions. Instead,
            builtin-functions are simple function instances, but with a
            builtin-code attribute.
            Most of the time, builtin functions should be pickled by attribute.
            But PyPy has flaky support for __qualname__, so some builtin
            functions such as float.__new__ will be classified as dynamic. For
            this reason only, we created this special routine. Because
            builtin-functions are not expected to have closure or globals,
            there is no additional hack (compared the one already implemented
            in pickle) to protect ourselves from reference cycles. A simple
            (reconstructor, newargs, obj.__dict__) tuple is save_reduced.  Note
            also that PyPy improved their support for __qualname__ in v3.6, so
            this routing should be removed when cloudpickle supports only PyPy
            3.6 and later.
            r@   N)r    rE   r  r$   r  r   r}   r  )r  r@   rvs      r   r  zPickler.save_pypy_builtin_func  sR    & ""r3<<1A1A3??SB
 Db*c*r+   NN)NNNNNr
   )Sr$   r;   rN   _dispatch_tablerK  r   r`  rS  TextIOWrapperrt  rr  Loggerrv  
RootLoggerrj  
memoryviewr{  r   staticmethodrG  r   rE  r    rV   rc  GetSetDescriptorTyperl  r!   rp  rn  rf  re  r  r}  r~  r   r   r   r  _collections_abc	dict_keysr  dict_valuesr  
dict_itemsr  rG   r   r   r  r   r  r>   r  abstractmethodabstractclassmethodabstractstaticmethodabstractpropertyr  dataclasses_FIELD_BASEr   copyregdispatch_tabler  r  r  r  r  r  dispatchr  rT  r  r0   r  structr  r  r  r  rE   __classcell__)r   s   @r   r  r    sJ   O#6OK (4OB$$%&4OGNN#*=OG&&'"4OJ 0OH$7OL! ,OH&2OENN#2KOE../(6OE$$%(6OE$$%.BOE**+'6OGOO$&5OFNN#2CO$../4GO$0013EO$//02DOD++-./4HOD--/013FOD,,./0*=OC&&'/BOC++,0COC,,-,<OC(()/KOK++,ow/E/EFNP67B#   ",	&f >>**//1 	B )-6;; 	40 %		+2 (5##$r+   r  c                 >    t        |||      j                  |        y)a+  Serialize obj as bytes streamed into file

    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication
    speed between processes running the same Python version.

    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python (although this is not always
    guaranteed to work because cloudpickle relies on some internal
    implementation details that can change from one Python version to the
    next).
    r  N)r  r  )r@   r  r  r  s       r   r  r    s     D8_EJJ3Or+   c                     t        j                         5 }t        |||      }|j                  |        |j	                         cddd       S # 1 sw Y   yxY w)a8  Serialize obj as a string of bytes allocated in memory

    protocol defaults to cloudpickle.DEFAULT_PROTOCOL which is an alias to
    pickle.HIGHEST_PROTOCOL. This setting favors maximum communication
    speed between processes running the same Python version.

    Set protocol=pickle.DEFAULT_PROTOCOL instead if you need to ensure
    compatibility with older versions of Python (although this is not always
    guaranteed to work because cloudpickle relies on some internal
    implementation details that can change from one Python version to the
    next).
    r  N)rS  BytesIOr  r  getvalue)r@   r  r  r  cps        r   dumpsr    sF     
 THoN
}}  s   /AAr
   )Fr  )r   r  collectionsr   r   r  r   r  r  rt   enumr   rS  r
  rr  rv   rT  r   platformr  r%   	threadingr    r   r   r   r}  r   HIGHEST_PROTOCOLr  ra   r'   WeakKeyDictionaryr   WeakValueDictionaryr   Lockr   r~  r   python_implementationr  r  rG   floatr   r  rS   r   r   r*   r.   r2   r9   rB   rL   rH   rX   rl   opmaprm   rn   ro   rw   HAVE_ARGUMENTEXTENDED_ARGr  r}   r>   r  r  rr   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r!  r*  rE  rG  rK  r`  rc  rf  rj  rl  rp  rt  rv  r{  r  r  r  r  r  r  r  r  r  r  r  r  _FIELDrA   _FIELD_CLASSVAR_FIELD_INITVARr  r  r  r  r  loadloadsCloudPicklerr1   r+   r   <module>r     sn  :x  - 
    
  	         
      
  **  5 
 #<'";";"= :w::< ,inn. !0!2 %x%%'61 U]]3347g779 $2N9+B!
H%P2.d ||N+_-ll=)M;7
!!  NN  " #DAqAw$!"A#
 ,+(!  
  
E) ' D&@>8
&$):&
$N$N@_ D0#
)*X50#
8<*!A)
6)+*.0/;D4 [//$$k&A&A##[%?%?$  2^5fnn ^5H	P ( kk6<<e r+   