B e]@sdZddlmZddlZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZyddlmZWnek rdZYnXe jZeZeZeZe dkZ dZ!e re"e#j$j%Z!ej&ddkr\ddl m'Z'ydd l(m)Z)Wn"ek rJdd l)m)Z)YnXe*fZ+d Z,d Z-n8e"e_.dd l m/Z'dd lm0Z)e1fZ+d Z,d Z-ddl2m3Z3eZ4ddZ5ddZ6ej&dddkrddl m7Z7n2ej&dddkrddl m7Z8ddZ7nddZ7ddZ9dWddZ:ddZ;d d!Zej&ddd&krLe>Z?e j@d'ZAe j@d(ZBe j@d)ZCeAeBeCfZDejEZEejFZFiZGx.ejHID] \ZJZKe"eKe"kreJeGeK<qWd*d+ZLej&dkrd,d-ZMnd.d-ZMd/d0ZNGd1d2d2e'ZOd3d4ZPd5d6ZQdXd7d8ZRdYd9d:ZSe jTZTe jUZUd;d<ZVd=d>ZWd?d@ZXdAdBZYdCdDZZdEdFZ[e[GdGdHdHe\Z]dIdJZ^dKdLZ_dZdMdNZ`dOdPZadQdRZbdSdTZcdUdVZddS)[aU This class is defined to override standard pickle functionality The goals of it follow: -Serialize lambdas and nested functions to compiled byte code -Deal with main module correctly -Deal with other non-serializable objects It does not include an unpickler, as standard python unpickling suffices. This module was extracted from the `cloud` package, developed by `PiCloud, Inc. `_. Copyright (c) 2012, Regents of the University of California. Copyright (c) 2009 `PiCloud, Inc. `_. 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. )print_functionN)partial)EnumPyPy)Pickler)StringIOFT)_Pickler)BytesIO) _find_specc Cs@t2t|}|dkr2tj}|t|<|t|<WdQRX|S)N)_DYNAMIC_CLASS_TRACKER_LOCK_DYNAMIC_CLASS_TRACKER_BY_CLASSgetuuidZuuid4hex_DYNAMIC_CLASS_TRACKER_BY_ID) class_defclass_tracker_idr@/tmp/pip-install-b8evvk6i/srsly/srsly/cloudpickle/cloudpickle.py_ensure_trackingls  rc Cs0|dk r,tt||}|t|<WdQRX|S)N)r r setdefaultr )rrrrr_lookup_class_or_trackvs r)r) _getattribute)rcCst||dfS)N)_py34_getattribute)objnamerrrrsrcCst||ddfS)N)getattr)rrrrrrsc Cszt|dd}|dk r|Sx\ttjD]J\}}|dks(|dkrBq(yt||d|krZ|SWq(tk rpYq(Xq(WdS)aUFind 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)r listsysmodulesitemsr Exception)rr module_namemodulerrr _whichmodules  r*cCs|dkrt|dd}|dkr(t|dd}t||}|dkr>dS|dkrJdStj|d}|dkrddSt|rpdSyt||\}}Wntk rdSX||kS)zDDetermine if obj can be pickled as attribute of a file-backed moduleN __qualname____name__Fr")r r*r$r%r _is_dynamicrAttributeError)rrr(r)obj2parentrrr _is_globals&   r1csht|}|dkrd|jfddt|D}|jr\x&|jD]}t|tjr<|t|O}qsz(_extract_code_globals..) _extract_code_globals_cacherco_names_walk_global_ops co_consts isinstancetypesCodeType_extract_code_globals)coZ out_namesconstr)r5rr>s   r>cCsg}x|D]}t|tjr t|dr |jr |jd}x\ttjD]N}|dk r@| |r@t |t |d d}|t |j s@|tj|q@Wq W|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__.N)r;r< ModuleTypehasattrrAr,r#r$r% startswithsetlensplitr8append)codeZtop_level_dependenciesZ subimportsxprefixrtokensrrr_find_imported_submoduless   rNcCs:tjdddkr||_nttidd|f}||dS)aZ Set the value of a closure cell. The point of this function is to set the cell_contents attribute of a cell after its creation. This operation is necessary in case the cell contains a reference to the function the cell belongs to, as when calling the function's constructor ``f = types.FunctionType(code, globals, name, argdefs, closure)``, closure will not be able to contain the yet-to-be-created f. In Python3.7, cell_contents is writeable, so setting the contents of a cell can be done simply using >>> cell.cell_contents = value In earlier Python3 versions, the cell_contents attribute of a cell is read only, but this limitation can be worked around by leveraging the Python 3 ``nonlocal`` keyword. In Python2 however, this attribute is read only, and there is no ``nonlocal`` keyword. For this reason, we need to come up with more complicated hacks to set this attribute. The chosen approach is to create a function with a STORE_DEREF opcode, which sets the content of a closure variable. Typically: >>> def inner(value): ... lambda: cell # the lambda makes cell a closure ... cell = value # cell is a closure, so this triggers a STORE_DEREF (Note that in Python2, A STORE_DEREF can never be triggered from an inner function. The function g for example here >>> def f(var): ... def g(): ... var += 1 ... return g will not modify the closure variable ``var```inplace, but instead try to load a local variable var and increment it. As g does not assign the local variable ``var`` any initial value, calling f(1)() will fail at runtime.) Our objective is to set the value of a given cell ``cell``. So we need to somewhat reference our ``cell`` object into the ``inner`` function so that this object (and not the smoke cell of the lambda function) gets affected by the STORE_DEREF operation. In inner, ``cell`` is referenced as a cell variable (an enclosing variable that is referenced by the inner function). If we create a new function cell_set with the exact same code as ``inner``, but with ``cell`` marked as a free variable instead, the STORE_DEREF will be applied on its closure - ``cell``, which we can specify explicitly during construction! The new cell_set variable thus actually sets the contents of a specified cell! Note: we do not make use of the ``nonlocal`` keyword to set the contents of a cell in early python3 versions to limit possible syntax errors in case test and checker libraries decide to parse the whole file. Nr)r _cell_setr)r$ version_info cell_contentsr< FunctionType_cell_set_template_code)cellvaluerPrrrcell_sets 9rWcCsdd}|j}trRt|j|j|j|j|j|j |j |j |j |j |j|j|jd}nBt|j|j|j|j|j|j|j |j |j |j |j |j|j|jd}|S)Ncsfdd|dS)NcsS)Nrr)rUrrXzI_make_cell_set_template_code.._cell_set_factory..r)rVr)rUr_cell_set_factoryWs z7_make_cell_set_template_code.._cell_set_factoryr)__code__PY2r<r= co_argcount co_nlocals co_stacksizeco_flagsco_coder:r8 co_varnames co_filenameco_nameco_firstlineno co_lnotab co_cellvarsco_kwonlyargcount)rZr?rTrrr_make_cell_set_template_codeVsFri)rrO STORE_GLOBAL DELETE_GLOBAL LOAD_GLOBALcCs tt|S)N)r r<)rrrr _builtin_typesrmccst|dd}trtt|}t|}d}d}xn||kr||}|d7}|tkr,||||dd|}d}|d7}|tkr|d}|tkr,||fVq,WdS) zs Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. rarYrriN)r r\mapordrG HAVE_ARGUMENT EXTENDED_ARG GLOBAL_OPS)rJni extended_argopr4rrrr9s"   r9ccs2x,t|D]}|j}|tkr ||jfVq WdS)zs Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. N)disget_instructionsopcodertarg)rJinstrrxrrrr9sc Cst|j}t|jdkr&|jdj}n$i}xt|jD]}||jq6Wg}xH|D]<\}}y||}||kr|||WqXtk rYqXXqXWx|D]}| |qW|S)zDRetrieve a copy of the dict of a class without the inherited methodsrnr) dict__dict__rG __bases__reversedupdater&rIKeyErrorpop)clsclsdictZinherited_dictbaseZ to_removerrVZ base_valuerrr_extract_class_dicts"   rc@seZdZejZdAddZddZddZeee <e rHdd Z e ee <d d Z e eej<d d Zeeej<dBddZeeej<ddZddZddZddZddZesddZeeej<eejdZeej Z!edj Z"eee<eee!<eee"<e#j$dddkree%j&Z'eee'<d d!Z(e(eej)<de*j+fd"d#Z,e,ee<e,eej-<d$d%Z.e.eej/<d&d'Z0e r|e0eej1<d(d)Z2e2ee3<d*d+Z4e4ee5<e4ee6<d,d-Z7ee8j9ekre7ee8j9<d.d/Z:ee8j;ekre:ee8j;<d0d1Zy eeeeD<d6d7ZEeEeeFjG<d8d9ZHeHeeIjJ<d:d;ZKeKeeIjL<eMed<rd=d>ZNeNeejO<d?d@ZPdS)C CloudPicklerNcCs&|dkr t}tj|||di|_dS)N)protocol)DEFAULT_PROTOCOLr__init__ globals_ref)selffilerrrrrszCloudPickler.__init__c Cs\|y t||Stk rV}z$d|jdkrDd}t|nWdd}~XYnXdS)N recursionrz?Could not pickle object as excessively deep recursion required.) inject_addonsrdump RuntimeErrorargspickle PicklingError)rremsgrrrrs  zCloudPickler.dumpcCs||dS)N)savetobytes)rrrrrsave_memoryviewszCloudPickler.save_memoryviewcCs|t|dS)N)rstr)rrrrr save_bufferszCloudPickler.save_buffercCs<t|r$|jt|jt|f|dn|jt|jf|ddS)z, Save a module as an import )rN)r- save_reducedynamic_subimportr,vars subimport)rrrrr save_modules zCloudPickler.save_modulecCstrt|drT|j|j|j|j|j|j|j|j |j |j |j |j |j|j|j|jf}q|j|j|j|j|j|j|j |j |j |j |j |j|j|j|jf}n<|j|j|j|j|j|j |j |j |j |j |j|j|j|jf}|jtj||ddS)z$ Save a code object co_posonlyargcount)rN)PY3rDr]rrhr^r_r`rar:r8rbrcrdrerf co_freevarsrgrr<r=)rrrrrrsave_codeobjects"        zCloudPickler.save_codeobjectcCsDt||drtj|||dStr6t|jtr6||S||SdS)z Registered 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. )rN) r1r save_globalPYPYr;r[builtin_code_typesave_pypy_builtin_funcsave_function_tuple)rrrrrr save_function!s   zCloudPickler.save_functioncCs4tj|ji|j|j|jf|jf}|j|d|idS)aSave 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. rN)r<rSr[r, __defaults__ __closure__rr)rrrvrrrr0s z#CloudPickler.save_pypy_builtin_funcc Cs|tdd|D}t|dd}|jt|j|j|||jt|df|dxdD]}||dqLWx|D]}||qfWdS)a Special handling for dynamic Enum subclasses Use a dedicated Enum constructor (inspired by EnumMeta.__call__) as the EnumMeta metaclass has complex initialization that makes the Enum subclasses hold references to their own instances. css|]}|j|jfVqdS)N)rrV)r2rrrr Osz2CloudPickler._save_dynamic_enum..r+N)r)_generate_next_value__member_names_ _member_map_ _member_type__value2member_map_) r~r r_make_skeleton_enumrr,r!rr)rrrmembersqualnameattrnamememberrrr_save_dynamic_enumHs    zCloudPickler._save_dynamic_enumc CsJt|}|ddd|krHddl}||\}}}}dd|D|d<d|ddi}t|dr|j|d<t|jtr||jnx|jD]}||dqW|d d}t|tr||d <|j } |j } | t | t j tdk rt|tr|||n,t|} |jt| |j|j|t|df|d | || t j| t jdS) zSave a class that can't be stored as module global. This method is used to serialize classes that are defined inside functions, or that otherwise can't be serialized as attribute lookups from global modules. __weakref__N _abc_implrcSsg|] }|qSrr)r2Zsubclass_weakrefrrr rsz3CloudPickler.save_dynamic_class..__doc__ __slots__r)r)rrabc _get_dumprDrr; string_typespropertyrwrite_rehydrate_skeleton_classrMARKr issubclassrtyper_make_skeleton_classr,rrTUPLEREDUCE) rrrrregistryr3 type_kwargskrrrtprrrsave_dynamic_classbs>            zCloudPickler.save_dynamic_classc Cs,t|r |jt|jf|ddS|j}|j}||\}}}}}} |t|tj t |t | |phd} |t|||dk rt|nd| f|tj|||||||j|j|j| d} t|drtjdkr|j| d<t|d r|j| d <t|d r |j| d <|| |tj|tjdS) a Pickles an actual func object. A func comprises: code, globals, defaults, closure, and dict. We extract and save these, injecting reducing functions at certain points to recreate the func object. Keep in mind that some of these pieces can contain a ref to the func itself. Thus, a naive save on these pieces could trigger an infinite loop of save's. To get around that, we first create a skeleton func object using just the code (this is safe, since this won't contain a ref to the func), and memoize it as soon as it's created. The other stuff can then be filled in later. )rNr)globalsdefaultsr~closure_valuesr)rdoc_cloudpickle_submodules__annotations__)rrO annotationsr+r__kwdefaults__ kwdefaults)is_tornado_coroutiner_rebuild_tornado_coroutine __wrapped__rrextract_func_data_fill_functionrrrN itertoolschainvalues_make_skel_funcrGrmemoizer!r,rrDr$rQrr+rr) rfuncrrrJ f_globalsrrdct base_globalsZ submodulesstaterrrrsH           z CloudPickler.save_function_tuplec Cs|j}t|}i}x$|D]}||jkr|j|||<qW|j}|jdk rXttt|jnd}|j}|j t |ji} | ikrx.dD]&} |jdk r| |jkr|j| | | <qW|||||| fS)z Turn the function into a tuple of data necessary to recreate it: code, globals, defaults, closure_values, dict N)rAr,__path____file__) r[r> __globals__rrr#rp_get_cell_contentsrrrid) rrrJZfunc_global_refsrvarrclosurerrrrrrrs     zCloudPickler.extract_func_datacCsnt|dddk }|r4t|j|jff}|j|d|iSt|d}|rbt|j|jff}|j|d|iSt||S)N__self__r __objclass__)r rr,rrDrrr)rrZis_boundrZ is_unboundrrrsave_builtin_function_or_method4s z,CloudPickler.save_builtin_function_or_methodfromhexg?r)rrcCs|t|j|jfS)N)rr rr,)rrrrrsave_getset_descriptorUsz#CloudPickler.save_getset_descriptorcCs|tdkr|jtd|dS|ttkr:|jttf|dS|ttkrX|jttf|dS|tkrv|jtt|f|dS|dk rtj|||dn(t||ds| |ntj|||ddS)z Save a "global". The name of this method is somewhat misleading: all types get dispatched here. N)N)r)r) rrEllipsisNotImplemented_BUILTIN_TYPE_NAMESrmrrr1r)rrrpackrrrrZs     zCloudPickler.save_globalcCsf|jdkr |t|j|jfnBtr@|jtj|j|jf|dn"|jtj|j|jt |jf|ddS)N)r) rrr Zim_classr,rr< MethodType__func__r)rrrrrsave_instancemethodts z CloudPickler.save_instancemethodc Cs(|j}|j|}|r$|||dS|j}|j}|j}t|dr^|}t|t ||nd}|t j |j r||x|D] }||qW|t j n4x|D] }||qW|t j|jd|jd||y |j} Wntk r|j} YnX| } t | ||| |t jdS)z8Inner logic to save instance. Based off pickle.save_instN__getinitargs__r ) __class__dispatchrmemorrrDrrGr _keep_aliverbinOBJINSTr!r,r __getstate__r.rBUILD) rrrfrrrrr|getstatestuffrrr save_insts>             zCloudPickler.save_instcCs$|jt|j|j|j|jf|ddS)N)r)rrfgetfsetfdelr)rrrrr save_propertyszCloudPickler.save_propertycCs |j}|jt||f|ddS)N)r)rrr)rrZ orig_funcrrrsave_classmethodszCloudPickler.save_classmethodcCs6Gddd}||}t|ts(|f}|tj|S)z5itemgetter serializer (needed for namedtuple support)c@seZdZddZdS)z+CloudPickler.save_itemgetter..DummycSs|S)Nr)ritemrrr __getitem__sz7CloudPickler.save_itemgetter..Dummy.__getitem__N)r,r!r+rrrrrDummysr)r;tupleroperator itemgetter)rrrr&rrrsave_itemgetters   zCloudPickler.save_itemgettercCs2Gdddt}g}||||tjt|S)zattrgetter serializerc@seZdZdddZddZdS)z+CloudPickler.save_attrgetter..DummyNcSs||_||_dS)N)attrsindex)rrrrrrrsz4CloudPickler.save_attrgetter..Dummy.__init__cSsXt|d}t|d}|dkr4t|}||nd|||g||<t|||S)NrrrB)object__getattribute__rGrIjoinr)rrrrrrrrs   z.Dummy.__getattribute__)N)r,r!r+rrrrrrrs r)rrr attrgetterr)rrrrrrrsave_attrgetters  zCloudPickler.save_attrgettercCsvy ddl}Wntk r(ddl}YnXt|dr>t|dsHtd|tjkrf|jt tdf|dS|tj kr|jt tdf|dS|tj krtd |j rtd t|d r| rtd d |jkrd|jkrtd|j|j}|}y(|}|d|}||Wn$tk rBtd|YnX||||||_||||dS)z Save a filerNrmodez5Cannot pickle files that do not map to an actual filestdout)rstderrzCannot pickle standard inputzCannot pickle closed filesisattyz+Cannot pickle files that map to tty objectsr+z7Cannot pickle files that are not opened for reading: %sz*Cannot pickle file %s as it cannot be read)r ImportErroriorDrrr$r!rr r"stdinclosedr#r rtellseekreadIOErrorrrr)rrZ pystringIOrretvalZcurloccontentsrrr save_files@            zCloudPickler.save_filecCs|tddS)Nr)r _gen_ellipsis)rrrrr save_ellipsis szCloudPickler.save_ellipsiscCs|tddS)Nr)r_gen_not_implemented)rrrrrsave_not_implementedsz!CloudPickler.save_not_implementedcCs|tjt|fdS)N)rweakrefWeakSetr#)rrrrr save_weaksetszCloudPickler.save_weaksetcCs|jtj|jf|ddS)N)r)rlogging getLoggerr)rrrrr save_loggerszCloudPickler.save_loggercCs|jtjd|ddS)Nr)r)rr8r9)rrrrrsave_root_logger#szCloudPickler.save_root_loggerMappingProxyTypecCs|jtjt|f|ddS)N)r)rr<r<r~)rrrrrsave_mappingproxy)szCloudPickler.save_mappingproxycCsdS)zPPlug in system. Register additional pickling functions if modules already loadedNr)rrrrr/szCloudPickler.inject_addons)N)N)Qr,r!r+rrcopyrrr memoryviewr\rbufferrr<rCrr=rrSrrrrrrrBuiltinFunctionTyperfloatrZclassmethod_descriptor_type__repr__Zwrapper_descriptor_typeZmethod_wrapper_typer$rQrupperZmethod_descriptorrGetSetDescriptorTypestructrr ClassTyperrr Z InstanceTyperrr classmethod staticmethodrrrrrr0r2r4r NameErrorr' TextIOWrapperrrr7r5r6r:r8Loggerr; RootLoggerrDr=r<rrrrrrs      TD4       -    )        rcCs0dtjkrdStjd}t|ds&dS||S)zj Return whether *func* is a Tornado coroutine function. Running coroutines are not supported. z tornado.genFis_coroutine_function)r$r%rDrN)rgenrrrr6s    rcCsddlm}||S)Nr)rO)ZtornadorO coroutine)rrOrrrrDs rcCst||d|dS)awSerialize 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. )rN)rr)rrrrrrrKs rcCs4t}zt||d}|||S|XdS)aSerialize 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. )rN)rrrgetvalueclose)rrrcprrrdumpsXs   rTcCst|tj|S)N) __import__r$r%)rrrrrqsrcCst|}|j||S)N)r<rCrr)rrmodrrrrvs  rcCstS)N)rrrrrr1|sr1cCstS)N)rrrrrr3sr3cCs y|jStk rtSXdS)N)rR ValueError_empty_cell_value)rUrrrrsrcCs|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``. r)rrrrinstances rYc@seZdZdZeddZdS)rXz sentinel for empty closures cCs|jS)N)r,)rrrr __reduce__sz_empty_cell_value.__reduce__N)r,r!r+rrHrZrrrrrXsrXcGst|dkr|d}|d}nt|dkrV|d}ddddg}tt||dd }nHt|d kr|d}dddd dg}tt||dd }ntd |f|j|d|d|_|d|_d |kr|d |_d|kr|d|_ d|kr|d|_ d |kr |d |_ d|kr |d|_ d|kr4|d|_ d|krH|d|j}|d k rx0t||dD]\}}|tk rht||qhW|S)zFills in the rest of function data into the skeleton function object The skeleton itself is create by _make_skel_func(). rrrnrrrr~rNr)z$Unexpected _fill_value arguments: %rrrrrrr)rGr~ziprWrrrrrrr,r!r+rrrrXrW)rrrkeyscellsrUrVrrrrsF                     rcsfddjdS)NcsS)Nrr)rUrrrXrYz"_make_empty_cell..r)rrr)rUr_make_empty_cellsr_cCsR|dkst|tri}t|d<|dkr.)r;rr`rranger<rS)rJZ cell_countrrrrrrs rcCs||||}t||S)aBuild 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. )r)Ztype_constructorrbasesrrextraskeleton_classrrrrs rcCsXd}x.|D]"\}}|dkr$|}qt|||qW|dk rTx|D]}||qBW|S)zwPut attributes from `class_dict` back on `skeleton_class`. See CloudPickler.save_dynamic_class for more info. Nr)r&setattrregister)rd class_dictrrattrsubclassrrrrs rc Csf|d}|j}|||} x|D]\} } | | | <q$W||||| } || _|dk r\|| _t|| S)a6Build 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. rN)r __prepare__r&__new__r!r+r) rbrrrr)rrcZ enum_basemetacls classdict member_name member_value enum_classrrrr&s  rc Cst|drdSt|dr|jdk r&dS|jdd}|rxytj|}Wn&tk rnd}t||Yq|X|j }nd}t |j||dkSddl }yNd}xD|j dD]4}|dk r|g}| ||\}}} |dk r|qWWntk rdSXdSdS) z^ Return True if the module is special module that cannot be imported by its name. rF__spec__NrBrzparent {!r} not in sys.modulesT)rDrqr, rpartitionr$r%rr&formatrr imprH find_modulerR) r) parent_namer0rpkgpathrtpathpartr  descriptionrrrr-Gs6   r-)N)N)N)N)er __future__rry functoolsrr'rr8r{rrplatformrFr$ tracebackr<r5r threadingenumrr&HIGHEST_PROTOCOLrWeakKeyDictionaryr WeakValueDictionaryrLockr python_implementationrrrrBrkr[rQr cStringIOr basestringrrr\rGr r rZimportlib._bootstrapr r7rrrrr*r1r>rNrWrirTopmaprjrkrlrtrrrsrrr&rvrmr9rrrrrrTloadloadsrrr1r3rrYrrXrr_rrrrr-rrrr*s             &/A-       f  A !