U e5dÕ!ã@sTdZddlZddlZddlmZGdd„deƒZeZzddlm Z Wne k r\dZ YnXdddgZ d d„Z iZ Zd d „Zedƒeeeeeeeeeeeeejeeƒeeƒejej fD] Z!eee!<qºe"ed dƒZ!e!dk räeee!<e#j ee#<e$j ee$<e%j ee%<e&j ee&<e dk �r e j ee <[[!dgfd d„Z'iZ(Zdd„Z)e)eedƒ<e)eeeƒ<e)eeeƒ<e)ee<e)ee<e)ee<e)ee<e)ee<e)ee<e)eej*<e)ee<e)eej<e)eej<e)eej <e)ee<e'fdd„Z+e+ee#<e'fdd„Z,e,ee<e'fdd„Z-e-ee$<e dk �re-ee <dd„Z.e.eej/<[dd„Z0ddde'fdd„Z1[[[ dS)aÍGeneric (shallow and deep) copying operations. Interface summary: import copy x = copy.copy(y) # make a shallow copy of y x = copy.deepcopy(y) # make a deep copy of y For module specific errors, copy.Error is raised. The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances). - A shallow copy constructs a new compound object and then (to the extent possible) inserts *the same objects* into it that the original contains. - A deep copy constructs a new compound object and then, recursively, inserts *copies* into it of the objects found in the original. Two problems often exist with deep copy operations that don't exist with shallow copy operations: a) recursive objects (compound objects that, directly or indirectly, contain a reference to themselves) may cause a recursive loop b) because deep copy copies *everything* it may copy too much, e.g. administrative data structures that should be shared even between copies Python's deep copy operation avoids these problems by: a) keeping a table of objects already copied during the current copying pass b) letting user-defined classes override the copying operation or the set of components copied This version does not copy types like module, class, function, method, nor stack trace, stack frame, nor file, socket, window, nor array, nor any similar types. Classes can use the same interfaces to control copying that they use to control pickling: they can define methods called __getinitargs__(), __getstate__() and __setstate__(). See the documentation for module "pickle" for information on these methods. éN)Údispatch_tablec@s eZdZdS)ÚErrorN)Ú__name__Ú __module__Ú __qualname__©rrú/usr/lib64/python3.8/copy.pyr7sr)Ú PyStringMapÚcopyÚdeepcopycCsÈt|ƒ}t |¡}|r||ƒSt|tƒr0t|ƒSt|ddƒ}|dk rL||ƒSt |¡}|dk rh||ƒ}nBt|ddƒ}|dk r†|dƒ}n$t|ddƒ}|rž|ƒ}n td|ƒ‚t|t ƒr¸|St |df|žŽS)zlShallow copy operation on arbitrary Python objects. See the module's __doc__ string for more info. Ú__copy__NÚ __reduce_ex__éÚ __reduce__z%un(shallow)copyable object of type %s) ÚtypeÚ_copy_dispatchÚgetÚ issubclassÚ_copy_immutableÚgetattrrrÚ isinstanceÚstrÚ _reconstruct)ÚxÚclsÚcopierÚreductorÚrvrrrr Bs,          cCs|S©Nr)rrrrrksrÚCodeTypec Cs |dkr i}t|ƒ}| ||¡}||k r,|St|ƒ}t |¡}|dk rR|||ƒ}n®t|tƒrht||ƒ}n˜t|ddƒ}|dk r†||ƒ}nzt |¡}|rž||ƒ}nBt|ddƒ}|dk r¼|dƒ}n$t|ddƒ}|rÔ|ƒ}n td|ƒ‚t |t ƒrð|}nt ||f|žŽ}||k �r|||<t ||ƒ|S)ziDeep copy operation on arbitrary Python objects. See the module's __doc__ string for more info. NÚ __deepcopy__r rrz"un(deep)copyable object of type %s) ÚidrrÚ_deepcopy_dispatchrÚ_deepcopy_atomicrrrrrrÚ _keep_alive) rÚmemoZ_nilÚdÚyrrrrrrrr €sD            ÿ   cCs|Srr©rr%rrrr#¶sr#cCs2g}||t|ƒ<|j}|D]}||||ƒƒq|Sr)r!Úappend)rr%r r'r)ÚarrrÚ_deepcopy_listÈs  r+csh‡‡fdd„|Dƒ}zˆt|ƒWStk r6YnXt||ƒD]\}}||k rBt|ƒ}qdqB|}|S)Ncsg|]}ˆ|ˆƒ‘qSrr)Ú.0r*©r r%rrÚ Òsz#_deepcopy_tuple..)r!ÚKeyErrorÚzipÚtuple)rr%r r'ÚkÚjrr-rÚ_deepcopy_tupleÑsr4cCs:i}||t|ƒ<| ¡D]\}}|||ƒ||||ƒ<q|Sr)r!Úitems)rr%r r'ÚkeyÚvaluerrrÚ_deepcopy_dictâs  r8cCst|ƒ|jt|j|ƒƒSr)rÚ__func__r Ú__self__r(rrrÚ_deepcopy_methodìsr;cCs>z|t|ƒ |¡Wn"tk r8|g|t|ƒ<YnXdS)aMKeeps a reference to the object x in the memo. Because we remember objects by their id, we have to assure that possibly temporary objects are kept alive by referencing them. We store a reference at the id of the memo, which should normally not be used unless someone tries to deepcopy the memo itself... N)r!r)r/r(rrrr$òs r$csbˆdk }|r$|r$‡‡fdd„|Dƒ}||Ž} |r<| ˆt|ƒ<|dk rÆ|rRˆ|ˆƒ}t| dƒrh|  |¡n^t|tƒrˆt|ƒdkrˆ|\}} nd} |dk r | j |¡| dk rÆ|  ¡D]\} } t | | | ƒq°|dk �r|rô|D]} ˆ| ˆƒ} |   | ¡qØn|D]} |   | ¡qø|dk �r^|�rF|D]&\} } ˆ| ˆƒ} ˆ| ˆƒ} | | | <�qn|D]\} } | | | <�qJ| S)Nc3s|]}ˆ|ˆƒVqdSrr)r,Úargr-rrÚ sz_reconstruct..Ú __setstate__é) r!Úhasattrr>rr1ÚlenÚ__dict__Úupdater5Úsetattrr))rr%ÚfuncÚargsÚstateZlistiterZdictiterr Zdeepr'Z slotstater6r7Úitemrr-rrsF               r)2Ú__doc__ÚtypesÚweakrefÚcopyregrÚ ExceptionrÚerrorZorg.python.corer Ú ImportErrorÚ__all__r rr&rrÚintÚfloatÚboolÚcomplexrr1ÚbytesÚ frozensetÚrangeÚsliceÚpropertyÚBuiltinFunctionTypeÚEllipsisÚNotImplementedÚ FunctionTypeÚrefÚtrÚlistÚdictÚsetÚ bytearrayr r"r#rr+r4r8r;Ú MethodTyper$rrrrrÚs’2   'ý        4            þ -