bg[ dZgdZddlZddlZddlZddlZddlmZmZm Z ddlm Z m Z m Z m Z mZmZmZmZmZmZmZddlmZmZddlZddlZejejZdZe ee e e fZd evr eed fz Zd Ze d eDZd Z!d Z"dZ# ddee$ej%fdeee e$fde&ddfdZ'ddZ(e'je(_GddZ)dZ*d dZ+ d!dee$ej%fdeee e$fdee fdZ,d!dZ-e,je-_ d"dee$ej%fde&de.fdZ/dD]Z0e1ee0e2e0[0dS)#z, Pickle and restore the intepreter session. ) dump_module load_moduleload_module_asdict dump_session load_sessionN)_dillPickler Unpickler) BuiltinMethodType FunctionType MethodType ModuleTypeTypeType_import_module_is_builtin_module_is_imported_module _main_module_reverse_typemap __builtin__)OptionalUnioncddlm}ddlm}||t|ti}t jD]\}}|dvst|tsd|vr||j t|<|j D]W\}}|j |||f|jt||||fX|S)zget map of imported modulesr) defaultdict)SimpleNamespace)by_nameby_id top_level)__main__ __mp_main__.) collectionsrtypesrlistsysmodulesitems isinstancerrid__dict__rappendr)rrmodmapmodnamemoduleobjnamemodobjs ]/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/dill/session.py _module_mapr2&s5''''''%%%%%% _ D!!k$F ;,,..HH 1 1 1FJ9W9W 1  g  +2F RZZ (%4466 H HOGV N7 # * *FG+< = = = LF $ + +VWg,F G G G G H M PyCapsuleType)ctypestyping subprocess threadingzconcurrent\.futures(\.\w+)?zmultiprocessing(\.\w+)?c#>K|]}tj|VdSN)recompile).0xs r1 r?>s*GGaBJqMMGGGGGGr3cp|j|D]#\}}||urtj||ur||fcS$t|ddt |t s"[t fdtDr;|jt|D] \}}}tj||ur||fcS!dS)z.lookup name or id of obj if module is imported __module__Nc3BK|]}|VdSr:) fullmatch)r=regexrAs r1r?z!_lookup_module..Gs/QQEEOOJ//QQQQQQr3NN) rr%r&getattrr(IMPORTED_AS_TYPESanyIMPORTED_AS_MODULESrr))r,nameobj main_moduler0r-r/rAs @r1_lookup_modulerM@s!>$/!! S==S[1DDD= lD11J#())(j.DQQQQ=PQQQQQ/E(. RWW(= ( ( $FGW{7#;66''''7 :r3c t}t|j}g}g}g}i}|jD]\} |ur|||< |jur |j||<#t fddDs$t trt r ||<ht|| |\}} |7| |kr| ||f| || |f | |j t |f#t$r ||<YwxYwt|t|jkrX|j|||_||_||_t%|ddt'|rd|_|S|S)Nc3 K|]}|uV dSr:)r= singletonrKs r1r?z!_stash_modules..[s(GGi !GGGGGGr3)NFT __loader__T)r2r__name__r*r'rHr(rrMr+rr)KeyErrorlenupdate__dill_imported__dill_imported_as__dill_imported_top_levelrFrrR) rLr,newmodimported imported_asimported_top_leveloriginalrJ source_moduler/rKs @r1_stash_modulesr`Ms  ]]F  , - -FHKH )//11)) c +  #HTNN K( ( (#_HTNN GGGG3FGGG G G )c:.. )3Ec3J3J ) HTNN%3FD#{%S%S "M7(d??OO]D$9::::&& w'EFFFF)&--v/?3/H$.OPPPP)))%(HTNNN) 8}}s;/0000x(((!)$/!+=( 6< . . 6;N{;[;[ 6 $F  s=D>c |jdD]#\}}||||j|<$|jdD]$\}}}||||j|<%|jdD]\}}t||j|<dS#t$rYdSwxYw)NrWrXrY)r*pop find_class __import__rT) unpicklerrLr-rJr/s r1_restore_modulesrfws (1556GHH M MMGT)2)=)=gt)L)LK  & &&1&:&>&>?S&T&T P P "GWd)2)=)=gw)O)OK  & &(1556QRR = =MGT)3G)<)>> import dill >>> squared = lambda x: x*x >>> dill.dump_module() # save state of __main__ to /tmp/session.pkl - Save the state of an imported/importable module: >>> import dill >>> import pox >>> pox.plus_one = lambda x: x+1 >>> dill.dump_module('pox_session.pkl', module=pox) - Save the state of a non-importable, module-type object: >>> import dill >>> from types import ModuleType >>> foo = ModuleType('foo') >>> foo.values = [1,2,3] >>> import math >>> foo.sin = math.sin >>> dill.dump_module('foo_session.pkl', module=foo, refimported=True) - Restore the state of the saved modules: >>> import dill >>> dill.load_module() >>> squared(2) 4 >>> pox = dill.load_module('pox_session.pkl') >>> pox.plus_one(1) 2 >>> foo = dill.load_module('foo_session.pkl') >>> [foo.sin(x) for x in foo.values] [0.8414709848078965, 0.9092974268256817, 0.1411200080598672] - Use `refimported` to save imported objects by reference: >>> import dill >>> from html.entities import html5 >>> type(html5), len(html5) (dict, 2231) >>> import io >>> buf = io.BytesIO() >>> dill.dump_module(buf) # saves __main__, with html5 saved by value >>> len(buf.getvalue()) # pickle size in bytes 71665 >>> buf = io.BytesIO() >>> dill.dump_module(buf, refimported=True) # html5 saved by reference >>> len(buf.getvalue()) 438 *Changed in version 0.3.6:* Function ``dump_session()`` was renamed to ``dump_module()``. Parameters ``main`` and ``byref`` were renamed to ``module`` and ``refimported``, respectively. Note: Currently, ``dill.settings['byref']`` and ``dill.settings['recurse']`` don't apply to this function. ))mainr.)byrefrhz The argument z has been renamed rlz. to distinguish it from dill.settings['byref']r!zboth z and z arguments were usedrkr )settingsprotocolN%r is not a modulewrite session.pklwbFT)warningswarnPendingDeprecationWarninglocals TypeErrorrbrmrr(strrrhasattrTEMPDIRopenr _original_mainr`_main_byref_recurse_session _first_pass_main_modifieddumpclose) rgr.rhkwdsold_parparmessagermrnrkfilepicklers r1rrs.tGWW  d????FwwLG'!!KK M'C-)B C C Cxx} WiWWW UVVV((7K00K XXff % %F"""""" #H D | D#  $d## dJ ' '5,t3444x!!$  7=011HHd##$11D11!%  (!$''D  "!%W-C!C T x   JJLLL x   JJLLLL  Fs 5A,F::Gc Ztjdtt|f||d|dS)Nz-dump_session() has been renamed dump_module())r.rh)rsrtrur)rgrkrlrs r1rr s9 MAC\]]]A5AADAAAAAr3c6eZdZdZdZdZdZdZdZdZ dS) _PeekableReaderz1lightweight stream wrapper that implements peek()c||_dSr:)stream)selfrs r1__init__z_PeekableReader.__init__s  r3c6|j|Sr:)rread)rns r1rz_PeekableReader.reads{"""r3c4|jSr:)rreadliners r1rz_PeekableReader.readlines{##%%%r3c4|jSr:)rtellrs r1rz_PeekableReader.tells{!!!r3c4|jSr:)rrrs r1rz_PeekableReader.closes{  """r3cP|j} t|dr||}||||}|||S#t tf$rtd|dwxYw)Nflushzstream is not peekable: %r) rryrrseekrAttributeErrorOSErrorNotImplementedError)rrrpositionchunks r1peekz_PeekableReader.peeks Vvw'' 7{{}}H KK ! ! !KKNNE KK ! ! !L( V V V%&BFKKQU U Vs A8B#B%N) rSrA __qualname____doc__rrrrrrrPr3r1rrsy;;###&&&"""### V V V V Vr3rcddl}t|dr|St|drt|ds& ||S#t$rYnwxYwt |S)z/return stream as an object with a peek() methodrNrrr)ioryBufferedReader Exceptionr)rrs r1_make_peekabler&s IIIvv FF # #(?(? $$V,, ,    D  6 " ""sA AAcpddlm}hd}d} ||dD]6\}}}|s!|jdvr|drd})|j|vr|cS7t d #t tf$r2}t|t r|Yd }~d St d |d }~wwxYw) zDidentify the name of the module stored in the given file-type objectr)genops>UNICODE BINUNICODESHORT_BINUNICODEF)GLOBALrrTz(reached STOP without finding main moduleNzunable to identify main module) pickletoolsrrrJendswithUnpicklingErrorr ValueErrorr() rrkrr found_importopcodeargposerrors r1_identify_moduler2s"""""";;;GLK &tyy~~ 6 6 N N FC ;"@@@ %566A#'L;'))JJJ*""LMM M  ,KKK e0 1 1 d6F44444>??UJ Ks$AA2"A22B5B0 B00B5c Td|vr@tjdt|td|d}|}t |dr|}n)|t tdz }t|d} t|}t|fi|}d|_ t||}|||}t|t rM|d r)t|d d }nt#|}|/t|tstd |z||_n|j}t'|}||d }|r|d d }d } |r1|r/t)| dddd|j|fz|s1|s/t)| dddd||jfz|j|kr/t)| dddd|j|fz|sd|jz} |t.j| <|} t |ds| t.j| =ne#t6t8f$rYnRwxYw#t |ds| t.j| =w#t6t8f$rYwwxYwxYw| |usJt;|||t<us||urdS|S)agUpdate the selected module (default is :py:mod:`__main__`) with the state saved at ``filename``. Restore a module to the state saved with :py:func:`dump_module`. The saved module can be :py:mod:`__main__` (e.g. an interpreter session), an imported module, or a module-type object (e.g. created with :py:class:`~types.ModuleType`). When restoring the state of a non-importable module-type object, the current instance of this module may be passed as the argument ``main``. Otherwise, a new instance is created with :py:class:`~types.ModuleType` and returned. Args: filename: a path-like object or a readable stream. If `None` (the default), read from a named file in a temporary directory. module: a module object or the name of an importable module; the module name and kind (i.e. imported or non-imported) must match the name and kind of the module stored at ``filename``. **kwds: extra keyword arguments passed to :py:class:`Unpickler()`. Raises: :py:exc:`UnpicklingError`: if unpickling fails. :py:exc:`ValueError`: if the argument ``main`` and module saved at ``filename`` are incompatible. Returns: A module object, if the saved module is not :py:mod:`__main__` or a module instance wasn't provided with the argument ``main``. Examples: - Save the state of some modules: >>> import dill >>> squared = lambda x: x*x >>> dill.dump_module() # save state of __main__ to /tmp/session.pkl >>> >>> import pox # an imported module >>> pox.plus_one = lambda x: x+1 >>> dill.dump_module('pox_session.pkl', module=pox) >>> >>> from types import ModuleType >>> foo = ModuleType('foo') # a module-type object >>> foo.values = [1,2,3] >>> import math >>> foo.sin = math.sin >>> dill.dump_module('foo_session.pkl', module=foo, refimported=True) - Restore the state of the interpreter: >>> import dill >>> dill.load_module() # updates __main__ from /tmp/session.pkl >>> squared(2) 4 - Load the saved state of an importable module: >>> import dill >>> pox = dill.load_module('pox_session.pkl') >>> pox.plus_one(1) 2 >>> import sys >>> pox in sys.modules.values() True - Load the saved state of a non-importable module-type object: >>> import dill >>> foo = dill.load_module('foo_session.pkl') >>> [foo.sin(x) for x in foo.values] [0.8414709848078965, 0.9092974268256817, 0.1411200080598672] >>> import math >>> foo.sin is math.sin # foo.sin was saved by reference True >>> import sys >>> foo in sys.modules.values() False - Update the state of a non-importable module-type object: >>> import dill >>> from types import ModuleType >>> foo = ModuleType('foo') >>> foo.values = ['a','b'] >>> foo.sin = lambda x: x*x >>> dill.load_module('foo_session.pkl', module=foo) >>> [foo.sin(x) for x in foo.values] [0.8414709848078965, 0.9092974268256817, 0.1411200080598672] *Changed in version 0.3.6:* Function ``load_session()`` was renamed to ``load_module()``. Parameter ``main`` was renamed to ``module``. See also: :py:func:`load_module_asdict` to load the contents of module saved with :py:func:`dump_module` into a dictionary. rkz.The argument 'main' has been renamed 'module'.Nz,both 'module' and 'main' arguments were usedrrqrbTz __runtime__.r!roz@can't update{} module{} %r with the saved state of{} module{} %rz importedz -type objectz__runtime__.%s)rsrtrurwrbryrxrzr{rr rrr( startswithr partitionrr}rrformatrSr%r&loadrrT NameErrorrfr) rgr.rrkrre pickle_mainis_main_importedis_runtime_mod error_msg runtime_mainloadeds r1rrIsL~~ < %     JKK K&!! Dx  $  7=011HHd##7d##d++d++ ! 'tT22 >>>Y%%% |tv~~t sCG'J5 JJ21J25%L K)(L)K=:L<K==Lc Xtjdtt|fd|i|dS)Nz.load_session() has been renamed load_module().r.)rsrtrur)rgrkrs r1rrs7 MBD]^^^........r3rVc d|vrtdt|dr|}n)|ttdz }t |d} t |}t |}tj |}t|}|r1|t|}|j |j n t|_|tj|<t!|fi|t|ds| |tj|=n|tj|<ni#t$$rYn]wxYw#t|ds| |tj|=w|tj|<w#t$$rYwwxYwxYwt||_|j S)ay Load the contents of a saved module into a dictionary. ``load_module_asdict()`` is the near-equivalent of:: lambda filename: vars(dill.load_module(filename)).copy() however, does not alter the original module. Also, the path of the loaded module is stored in the ``__session__`` attribute. Args: filename: a path-like object or a readable stream. If `None` (the default), read from a named file in a temporary directory. update: if `True`, initialize the dictionary with the current state of the module prior to loading the state stored at filename. **kwds: extra keyword arguments passed to :py:class:`Unpickler()` Raises: :py:exc:`UnpicklingError`: if unpickling fails Returns: A copy of the restored module's dictionary. Note: If ``update`` is True, the corresponding module may first be imported into the current namespace before the saved state is loaded from filename to the dictionary. Note that any module that is imported into the current namespace as a side-effect of using ``update`` will not be modified by loading the saved module in filename to a dictionary. Example: >>> import dill >>> alist = [1, 2, 3] >>> anum = 42 >>> dill.dump_module() >>> anum = 0 >>> new_var = 'spam' >>> main = dill.load_module_asdict() >>> main['__name__'], main['__session__'] ('__main__', '/tmp/session.pkl') >>> main is globals() # loaded objects don't reference globals False >>> main['alist'] == alist True >>> main['alist'] is alist # was saved by value False >>> main['anum'] == anum # changed after the session was saved False >>> new_var in main # would be True if the option 'update' was set False r.z@'module' is an invalid keyword argument for load_module_asdict()rNrqr)rwryrxrzr{rrr%r&getrrr*rVr __builtins__rrr __session__)rgrVrr main_nameold_mainrks r1rrsp4Z[[[x  $  7=011HHd##d##$T** ;??9--)$$  ,))44 M !2 3 3 3 3 +D !% ID!!D!!!x((  JJLLL K **)1 I&    D x((  JJLLL K **)1 I&&    D 8}}D =sOB'E D== E  E  %F#3FF#FF# F F#F  F#)rMr2rfr`rr)NNFr:rE)NF)3r__all__r;osr%rsdillrr r r r rrrrrrrrrr6rrpathlibtempfilePurePath gettempdirrzr2rGrItuplerMr`rfrxPathLikeboolrrrrrrrdictrrJsetattrglobalsrPr3r1rs     **********#""""""" ' .8.00 1 1& <EVW&&&*?;==[eGG3FGGGGG   (((T    )-/3C C C$%C U:s?+ ,C C  C C C C LBBBB#* VVVVVVVV0 # # #KKKK0)-/3rrC$%r U:s?+ ,rj rrrrj////#* )-XXC$%X X XXXXz **D GE44))))DDr3