/ lib / ipykernel / pickleutil.pyc
pickleutil.pyc
  1  o

  2  0��ce1�@s�UdZddlZddlZejdedd�ddlZddladdlZddlm	Z	ddl
  3  mZddlm
Z
dd	lmZeZeZtjZd:d
  4  d�Ze�Zdd
�Zdd�Zdd�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gd d!�d!e!�Z"Gd"d#�d#e!�Z#d:d$d%�Z$d&d'�Z%d(d)�Z&d*d+�Z'd,d-�Z(e)e*e+fZ,d.d/�Z-d:d0d1�Z.d:d2d3�Z/d:d4d5�Z0d6e e	ee1e!ee#eeee'iZ2eeur�e"e2e<ed7d8�e3e/iZ4ej5eej6fe7d9<e2��Z8e4��Z9dS);z>Pickle related utilities. Perhaps this should be called 'can'.�Nz@ipykernel.pickleutil is deprecated. It has moved to ipyparallel.�)�
  5  stacklevel)�FunctionType)�codeutil)�
  6  get_logger)�import_itemcs�fdd�}t|jd�S)zUthe type of a closure cell doesn't seem to be importable,
  7      so just create one
  8      c��S�N�r
  9  ��ar
 10  ��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\ipykernel\pickleutil.py�inner#�z_get_cell_type.<locals>.innerr)�type�__closure__)rrr
 11  rr
�_get_cell_typesrcCs2t|t�rtd�}t|j|j|j|j�}d|_|S)z�decorator for making functions appear as interactively defined.
 12      This results in the function being linked to the user_ns as globals()
 13      instead of the module globals().
 14      �__main__)�
 15  isinstancer�
 16  __import__�__code__�__dict__�__name__�__defaults__�
 17  __module__)�fZmainmodr
 18  r
 19  r
�interactive0s
 20  �rcC�Fddl}|azddlm}Wn	tyYnw||_t�td�dS)zquse dill to expand serialization support
 21  
 22      adds support for object methods and closures to serialization.
 23      rN��	serialize)�dill�pickle�	ipykernelr�ImportError�can_map�popr)r rr
 24  r
 25  r
�use_dillEs�r&cCr)zxuse cloudpickle to expand serialization support
 26  
 27      adds support for object methods and closures to serialization.
 28      rNr)�cloudpickler!r"rr#r$r%r)r'rr
 29  r
 30  r
�use_cloudpickle^s�r(c@s eZdZddd�Zddd�ZdS)�CannedObjectNcCsL|pg|_t�|�|_t|�|_|D]}t|j|tt||���qg|_dS)a�can an object for safe pickling
 31  
 32          Parameters
 33          ----------
 34          obj
 35              The object to be canned
 36          keys : list (optional)
 37              list of attribute names that will be explicitly canned / uncanned
 38          hook : callable (optional)
 39              An optional extra callable,
 40              which can do additional processing of the uncanned object.
 41  
 42          Notes
 43          -----
 44          large data may be offloaded into the buffers list,
 45          used for zero-copy transfers.
 46          N)�keys�copy�obj�can�hook�setattr�getattr�buffers)�selfr,r*r.�keyr
 47  r
 48  r
�__init__ys
 49  
 50  
 51  zCannedObject.__init__cCs\|duri}|j}|jD]}t||tt||�|��q|jr+t|j|�|_|�||�|jSr	)r,r*r/�uncanr0r.)r2�gr,r3r
 52  r
 53  r
�
 54  get_object�s
 55  zCannedObject.get_object)NNr	�rr�__qualname__r4r7r
 56  r
 57  r
 58  r
r)xs
 59  r)c@s*eZdZdZdd�Zdd�Zd	dd�ZdS)
 60  �	Referencez/object for wrapping a remote reference by name.cCs&t|t�std|��||_g|_dS)Nzillegal name: %r)r�str�	TypeError�namer1)r2r=r
 61  r
 62  r
r4�s
 63  
 64  zReference.__init__cCs
 65  d|jS)Nz<Reference: %r>)r=)r2r
 66  r
 67  r
�__repr__�s
 68  zReference.__repr__NcCs|duri}t|j|�Sr	)�evalr=)r2r6r
 69  r
 70  r
r7�szReference.get_objectr	)rrr9�__doc__r4r>r7r
 71  r
 72  r
 73  r
r:�s
 74  r:c@s"eZdZdZdd�Zddd�ZdS)�
 75  CannedCellzCan a closure cellcCst|j�|_dSr	)r-�
cell_contents)r2�cellr
 76  r
 77  r
r4�szCannedCell.__init__Ncs"t|j|���fdd�}|jdS)Ncrr	r
 78  r
 79  �rBr
 80  r
r�rz$CannedCell.get_object.<locals>.innerr)r5rBr)r2r6rr
 81  rDr
r7�s
 82  zCannedCell.get_objectr	)rrr9r@r4r7r
 83  r
 84  r
 85  r
rA�srAc@�&eZdZdd�Zdd�Zddd�ZdS)	�CannedFunctioncCs~|�|�|j|_||jrdd�|jD�|_nd|_||j}|r-tdd�|D��|_nd|_|jp4d|_	|j
 86  |_
 87  g|_dS)NcS�g|]}t|��qSr
 88  �r-)�.0�fdr
 89  r
 90  r
�
 91  <listcomp>��z+CannedFunction.__init__.<locals>.<listcomp>css�|]}t|�VqdSr	rH�rIrCr
 92  r
 93  r
�	<genexpr>�s�z*CannedFunction.__init__.<locals>.<genexpr>r)�_check_typer�coder�defaultsr�tuple�closurer�modulerr1)r2rrSr
 94  r
 95  r
r4�s
 96  
 97  zCannedFunction.__init__cC�t|t�s	Jd��dS)NzNot a function type)rr�r2r,r
 98  r
 99  r
rO��zCannedFunction._check_typeNcs�|j�d�st|j�tj|jj��duri�|jr(t�fdd�|jD��}nd}|jr:t�fdd�|jD��}nd}t	|j
100  �|j||�}|S)N�__c3��|]}t|��VqdSr	�r5)rIZcfd�r6r
101  r
rN���z,CannedFunction.get_object.<locals>.<genexpr>c3rYr	rZrMr[r
102  r
rN�r\)rT�
103  startswithr�sys�modulesrrQrRrSrrPr)r2r6rQrSZnewFuncr
104  r[r
r7�s
105  zCannedFunction.get_objectr	�rrr9r4rOr7r
106  r
107  r
108  r
rF�srFc@rE)	�CannedClasscCs�|�|�|j|_t|t�|_i|_|j��D]\}}|dvr't	|�|j|<q|jr.g}n|�
109  �}dd�|dd�D�|_g|_dS)N)�__weakref__rcSrGr
110  rH)rI�cr
111  r
112  r
rK�rLz(CannedClass.__init__.<locals>.<listcomp>�)
rOrr=rrZ	old_style�_canned_dictr�itemsr-�mro�parentsr1)r2�cls�k�vrgr
113  r
114  r
r4�s
115  �
116  zCannedClass.__init__cCrU)NzNot a class type)r�
117  class_typerVr
118  r
119  r
rO�rWzCannedClass._check_typeNcs0t�fdd�|jD��}t|j|t|j�d��S)Nc3rYr	rZ)rI�pr[r
120  r
rNr\z)CannedClass.get_object.<locals>.<genexpr>r[)rRrhrr=�
121  uncan_dictre)r2r6rhr
122  r[r
r7szCannedClass.get_objectr	r`r
123  r
124  r
125  r
ra�srac@seZdZdd�Zddd�ZdS)�CannedArraycCs�ddlm}|j|_|jjr|jjn|jj|_d|_t|j�dkr%d|_n|jdkr.d|_n|jjrBt	dd�|jj�
126  �D��rBd|_|jrOt�|t
�g|_dS||dd�}t|�g|_dS)	Nr)�ascontiguousarrayFT�Ocss�|]	\}}|dkVqdS)rqNr
127  )rI�dt�szr
128  r
129  r
rNs�z'CannedArray.__init__.<locals>.<genexpr>��dtype)�numpyrp�shaperu�fields�descrr;�pickled�sum�any�valuesr!�dumps�PICKLE_PROTOCOLr1�buffer)r2r,rpr
130  r
131  r
r4s
132  "zCannedArray.__init__NcCs<ddlm}|jd}|jrt�|�S|||jd��|j�S)Nr)�
133  frombufferrt)	rvr�r1rzr!�loadsru�reshaperw)r2r6r��datar
134  r
135  r
r7s
136  
137  
138  zCannedArray.get_objectr	r8r
139  r
140  r
141  r
rosroc@sBeZdZedejeeejfdefdd��Z	dd�Z
142  d
143  dd	�ZdS)�CannedBytes�buf�returncCs(t|t�r	|��St|t�st|�S|S)z+Cast a buffer or memoryview object to bytes)r�
144  memoryview�tobytes�bytes)r�r
145  r
146  r
�wrap)s
147  
148  
149  zCannedBytes.wrapcCs|g|_dSr	)r1rVr
150  r
151  r
r42szCannedBytes.__init__NcCs|jd}|�|�S)Nr)r1r�)r2r6r�r
152  r
153  r
r75s
154  
155  zCannedBytes.get_objectr	)rrr9�staticmethod�typing�Unionr�r��
SupportsBytesr�r4r7r
156  r
157  r
158  r
r�(s
159  "r�c@�eZdZeZdS)�CannedBufferN)rrr9r�r�r
160  r
161  r
162  r
r�:�r�c@r�)�CannedMemoryViewN)rrr9r�r�r
163  r
164  r
165  r
r�>r�r�c	Cs�t�}|�d�t|���D]3\}}t|t�rAzt|�}Wnty9|r2||vr2|jd|dd�|�	|�Yqw|�	|�||<qdS)z(import any string-keys in a type mappingzImporting canning mapz canning class not importable: %rT)�exc_infoN)
166  r�debug�listrfrr;r�	Exception�errorr%)�mapping�original�logr3�_rir
167  r
168  r
�_import_mappingGs
169  
170  ���r�cCs6t|t�r|D]}t|�|urdSqdSt|�|uS)zNlike isinstance(obj, check), but strict
171  
172      This won't catch subclasses.
173      TF)rrRr)r,�checkrir
174  r
175  r
�istypeXs
176  �r�cCsXd}t��D]\}}t|t�rd}nt||�r||�Sq|r*ttt�t|�S|S)zprepare an object for picklingFT)r$rfrr;r�r��_original_can_mapr-)r,�
import_neededriZcannerr
177  r
178  r
r-fs
179  
180  �
181  r-cCs t|t�r|jdkrt|�S|S)Nr)rrlrra)r,r
182  r
183  r
�	can_class{sr�cCs4t|t�ri}|��D]
184  \}}t|�||<q|S|S)zcan the *values* of a dict)r��dictrfr-)r,�newobjrjrkr
185  r
186  r
�can_dict�s
187  r�cCs(t|t�rt|�}|dd�|D��S|S)zcan the elements of a sequencecSrGr
188  rH�rI�ir
189  r
190  r
rK�rLz can_sequence.<locals>.<listcomp>�r��sequence_typesr)r,�tr
191  r
192  r
�can_sequence�s
193  r�cCs\d}t��D]\}}t|t�rd}n
t||�r|||�Sq|r,ttt�t||�S|S)zinvert canningFT)�	uncan_maprfrr;r��_original_uncan_mapr5)r,r6r�riZuncannerr
194  r
195  r
r5�s
196  
197  �
198  
199  r5cCs6t|t�ri}|��D]\}}t||�||<q|S|Sr	)r�r�rfr5)r,r6r�rjrkr
200  r
201  r
rn�s
202  rncs,t|t�rt|�}|�fdd�|D��S|S)Ncsg|]}t|���qSr
203  rZr�r[r
204  r
rK�sz"uncan_sequence.<locals>.<listcomp>r�)r,r6r�r
205  r[r
�uncan_sequence�s
206  r�z
numpy.ndarraycCs
207  |�|�Sr	)r7)r,r6r
208  r
209  r
�<lambda>�s
210  r�r�r	):r@r��warnings�warn�DeprecationWarningr+r!r^�typesr�ipyparallel.serializer�
traitlets.logr�traitlets.utils.importstringrr�r�rrl�DEFAULT_PROTOCOLrr�	cell_typerr&r(r)r:rArFraror�r�r�r�r�r-r�r�r�rR�setr�r�r5rnr�r�r$r�r��Dict�Any�__annotations__r�r�r
211  r
212  r
213  r
�<module>sp�
214  (,!
215  	
216  
217  	
218  
219  
220  ��