Qf bdZddlZddlZddlmZGddeZeZgdZdZ ixZ Z dZ ejeeeeeeeeeeeeej4ej6ej8ej:ej<ej>fD]Z e e e < e!je e!<e"je e"<e#je e#<e$je e$<[ [ dgfd Z%ixZ&Z d Z'e'e ej<e'e ej6<e'e ej8<e'e e<e'e e<e'e e<e'e e<e'e e<e'e e<e'e ej<<e'e e<e'e e<e'e ej4<e'e ej:<e'e ej><e'e e<e%fd Z(e(e e!<e%fd Z)e)e e<e%fd Z*e*e e"<dZ+e+e ejX<[ dZ- de%ddZ.[[y)aGeneric (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 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 eZdZy)ErrorN)__name__ __module__ __qualname__+/opt/alt/python312/lib64/python3.12/copy.pyrr7sr r)rcopydeepcopyct|}tj|}|r||St|tr t |St |dd}|||St j|}| ||}n=t |dd}| |d}n%t |dd}|r|}ntd|zt|tr|St|dg|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_dispatchget issubclass_copy_immutablegetattrrr isinstancestr _reconstruct)xclscopierreductorrvs r r r =s q'C    $F ay#tq!! S*d +F ay!!#&H a[1ot4  !Bq,5HZCcIJJ"c 4 %" %%r c|SNr )rs r rrf Hr c:|i}t|}|j||}||ur|St|}tj|}| |||}nt |tr t ||}nt |dd}| ||}n}tj|}|r ||}n=t |dd}| |d}n%t |dd}|r|}ntd|zt|tr|}n t||g|}||ur|||<t|||S)ziDeep copy operation on arbitrary Python objects. See the module's __doc__ string for more info. N __deepcopy__rrrz"un(deep)copyable object of type %s) idrr_deepcopy_dispatchr_deepcopy_atomicrrrrrr _keep_alive) rmemo_nildyrrrr s r r r vs9  | 1A DA} q'C  # #C (F  1dO c4  D)AQ5F!4L)--c2!!B&q/4@H+%a[#*1lD#A#!)B"' Ds J#LLb#&A$Q2r2A zQAt Hr c|Sr"r rr*s r r(r(r#r cjg}||t|<|j}|D]}|||||Sr")r&append)rr*r r-r1as r _deepcopy_listr3s; ADAK XXF x4 ! Hr c|Dcgc] }||| }} |t|Scc}w#t$rYnwxYwt||D]\}}||us t|}|S|}|Sr")r&KeyErrorziptuple)rr*r r2r-kjs r _deepcopy_tupler:s$%&Aq!T AA& BqE{ '    Aq 1 A:aA  H   Hs& + 77c|i}||t|<|jD]\}}|||||||<|Sr")r&items)rr*r r-keyvalues r _deepcopy_dictr?sE ADAKggi U!)%!6(3  Hr cbt||jt|j|Sr")r__func__r __self__r/s r _deepcopy_methodrCs$ 471::x D9 ::r c| |t|j|y#t$r|g|t|<YywxYw)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&r1r5r/s r r)r)s; RXa sRXs  ;;)r cndu}|r|r fd|D}||} |r| t|<||r |}t| dr| j|njt|trt |dk(r|\}} nd} || j j|| %| jD]\} } t| | | |<|r"|D]} | } | j| n|D]} | j| |4|r#|D]\} } | } | } | | | <| S|D] \} } | | | < | S)Nc30K|] }|ywr"r ).0argr r*s r z_reconstruct..s4td#ts __setstate__) r&hasattrrJrr7len__dict__updater<setattrr1)rr*funcargsstatelistiterdictiterr deepr- slotstater=r>items ` ` r rrsd t D 4t4 d A RU   UD)E 1n % NN5 !%'CJ!O#( y   !!%($"+//"3JCAsE*#4  d+!!! & UsD) -#' H' U#' Hr )NNN)/__doc__typesweakrefcopyregr Exceptionrerror__all__r rr,rNoneTypeintfloatboolcomplexrr7bytes frozensetrrangeslicepropertyBuiltinFunctionType EllipsisTypeNotImplementedType FunctionTypeCodeTypereftlistdictset bytearrayr r'r(r3r:r?rC MethodTyper)rr r r rvs+0d " I   '$&N ..#udGS% D%  # #U%7%7  " "E$6$6 ++  A AaD   ))$ ))$ #~~) q2 hQ $%..(%.% # % $ ' % #$%.. $ %/%(%!'++( %-  $&.  %%- $;&%"6:+ %+ Z 7r