3
AAd]z1  ã               @   sJ   d Z ddlZddlmZmZmZmZmZmZ ej	e
ƒZG dd„ deƒZdS )zH A record of refactorings to be performed during unpickling of objects.
é    N)ÚDictÚHasPrivateTraitsÚIntÚListÚTupleÚStrc               @   sä   e Zd ZdZeeeeƒeeeƒƒZeeeeeƒe	ƒZ
eeeeƒeƒZdZeeeeƒeƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%S )&ÚUpdaterzL A record of refactorings to be performed during unpickling of objects.
    Z_enthought_pickle_versionc             C   s   ||f| j ||f< dS )z• Adds a mapping from the class with the source name in the source
            module to the class with the target name in the target module.
        N)Ú	class_map)ÚselfÚsource_moduleÚsource_nameÚtarget_moduleZtarget_name© r   úy/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/apptools-4.4.0-py3.6.egg/apptools/sweet_pickle/updater.pyÚadd_mappingR   s    zUpdater.add_mappingc             C   s   | j |||j|jƒ dS )zˆ Convenience method to add a mapping, from the class with the
            source name in the source module to the target class.
        N)r   Ú
__module__Ú__name__)r
   r   r   Ztarget_classr   r   r   Úadd_mapping_to_class[   s    zUpdater.add_mapping_to_classc             C   s"   x|D ]}| j ||||ƒ qW dS )z¤ Adds mappings, from the specified source module to the specified
            target module, for each of the class names in the specified
            list.
        N)r   )r
   r   r   Zclass_namesÚnamer   r   r   Úadd_mappingsc   s    
zUpdater.add_mappingsc             C   s<   |||f}| j j|g ƒ}|dd… }|j|ƒ || j |< dS )aS   Adds the specified function as a state function to be called to
            convert an instance of the class with the specified name within
            the specified module *TO* the specified version.

            Note that the framework handles calling of state functions to make
            the smallest version jumps possible.
        N)Ústate_functionsÚ
setdefaultÚappend)r
   Úmoduler   Útarget_versionÚfunctionÚkeyÚlistr   r   r   Úadd_state_functionl   s
    

zUpdater.add_state_functionc             C   s   | j |j|j||ƒ dS )z½ Convenience method to add the specified function as a state
            function to be called to convert an instance of the specified
            class *TO* the specified version.
        N)r   r   r   )r
   Úklassr   r   r   r   r   Úadd_state_function_for_class|   s    z$Updater.add_state_function_for_classc             C   s   || j ||f< dS )z“ Adds the specified attribute name as the version attribute for the
            class within the specified module with the specified name.
        N)Úversion_attribute_map)r
   r   r   Úattribute_namer   r   r   Údeclare_version_attribute…   s    z!Updater.declare_version_attributec             C   s   | j |j|j|ƒ dS )z} Covenience method to add the specified attribute name as the
            version attribute for the specified class.
        N)r#   r   r   )r
   r   r"   r   r   r   Ú#declare_version_attribute_for_classŒ   s    z+Updater.declare_version_attribute_for_classc             C   s   | j j||f| jƒS )z€ Returns the name of the version attribute for the class of the
            specified name within the specified module.
        )r!   ÚgetÚ_default_version_attribute)r
   r   r   r   r   r   Úget_version_attribute”   s    zUpdater.get_version_attributec             C   s   ||f| j kS )zŒ Returns True if this updater contains a class mapping for
            the class identified by the specified module and class name.
        )r	   )r
   r   r   r   r   r   Úhas_class_mappingœ   s    zUpdater.has_class_mappingc             C   s   ||f| j kS )z� Returns True if this updater contains any state functions for
            the class identified by the specified module and class name.
        )Ú_state_function_classes)r
   r   r   r   r   r   Úhas_state_function£   s    zUpdater.has_state_functionc             C   s€   | j j|j ƒ | jj|jƒ x^t|jjƒ ƒD ]L\}}t|tƒr,t|ƒdkr,| jj|g ƒ}|dd… }|j	|ƒ || j|< q,W dS )zk Merges the mappings and state functions from the specified updater
            into this updater.
        r   N)
r	   Úupdater!   r   r   ÚitemsÚ
isinstanceÚlenr   Úextend)r
   Úupdaterr   ÚvalueÚfuncsr   r   r   Úmerge_updaterª   s    
zUpdater.merge_updaterc             C   s   t jd||| ƒ d S )Nz3Detected class_map change from [%s] to [%s] in [%s])ÚloggerÚdebug)r
   ÚoldÚnewr   r   r   Ú_class_map_changedÀ   s    zUpdater._class_map_changedc             C   s‚   x|j D ]}tjd|| ƒ qW x2t|jjƒ ƒD ] \}}tjd||| j| | ƒ q.W x*t|jjƒ ƒD ]\}}tjd||| ƒ qbW d S )Nz,Detected [%s] removed from class_map in [%s]z+Detected [%s] changed from [%s] to [%s] in zclass_map in [%s]z,Detected mapping from [%s] to [%s] added to z<Detected [%s] changed from [%s] to [%s] in class_map in [%s]z=Detected mapping from [%s] to [%s] added to class_map in [%s])Úremovedr4   r5   r   Úchangedr,   r	   Úadded)r
   ÚeventÚoÚkÚvr   r   r   Ú_class_map_items_changedÅ   s    
z Updater._class_map_items_changedc       
      C   sj   t jd||| ƒ | jjƒ  xJt|jƒ ƒD ]:\}}|\}}}||f}| jj|dƒ}	|	t|ƒ | j|< q(W d S )Nz3Detected state_functions changed from [%s] to [%s] zin [%s]r   z:Detected state_functions changed from [%s] to [%s] in [%s])r4   r5   r)   Úclearr   r,   r   r.   )
r
   r6   r7   r   r1   r   r   ÚversionZ	klass_keyÚcountr   r   r   Ú_state_functions_changedÑ   s    

z Updater._state_functions_changedc       
      C   s’  xˆt |jjƒ ƒD ]v\}}tjd|| ƒ |\}}}||f}| j| t|ƒ }|dk rjtjd	||ƒ | j|= q|dkr|| j|= q|| j|< qW x¢t |jjƒ ƒD ]�\}}| j	| }	tjd
|||	| ƒ |\}}}||f}| j| t|ƒ t|	ƒ }|dk �rtjd||ƒ | j|= qš|dk�r | j|= qš|| j|< qšW x^t |j
jƒ ƒD ]L\}}tjd||| ƒ |\}}}||f}| jj|dƒt|ƒ }|| j|< �q>W d S )Nz2Detected [%s] removed from state_functions in [%s]r   z.Unexpectedly reached negative reference count zvalue of [%s] for [%s]z.Detected [%s] changed in state_functions from z[%s] to [%s] in [%s]z*Detected mapping of [%s] to [%s] added to zstate_functions in [%s]zDUnexpectedly reached negative reference count value of [%s] for [%s]zBDetected [%s] changed in state_functions from [%s] to [%s] in [%s]zDUnexpectedly reached negative reference count value of [%s] for [%s]zADetected mapping of [%s] to [%s] added to state_functions in [%s])r   r9   r,   r4   r5   r)   r.   Úwarnr:   r   r;   r   )
r
   r<   r>   r?   r   r   rB   r   rC   r1   r   r   r   Ú_state_functions_items_changedà   sD    











z&Updater._state_functions_items_changedc             C   s   t jd||| ƒ d S )Nz0Detected version_attribute_map change from [%s] zto [%s] in [%s]z?Detected version_attribute_map change from [%s] to [%s] in [%s])r4   r5   )r
   r6   r7   r   r   r   Ú_version_attribute_map_changed  s    z&Updater._version_attribute_map_changedc             C   s^   x|j D ]}tjd|| ƒ qW x|jD ]}tjd|| ƒ q&W x|jD ]}tjd|| ƒ qDW d S )	Nz1Detected [%s] removed from version_attribute_map zin [%s]z/Detected [%s] changed in version_attribute_map z0Detected [%s] added to version_attribute_map in z[%s]z8Detected [%s] removed from version_attribute_map in [%s]z6Detected [%s] changed in version_attribute_map in [%s]z4Detected [%s] added to version_attribute_map in [%s])r9   r4   r5   r:   r;   )r
   r<   r=   r   r   r   Ú$_version_attribute_map_items_changed#  s    z,Updater._version_attribute_map_items_changedN)r   r   Ú__qualname__Ú__doc__r   r   r   r	   r   r   r   r!   r&   r)   r   r   r   r   r    r#   r$   r'   r(   r*   r3   r8   r@   rD   rF   rG   rH   r   r   r   r   r      s.   					>r   )rJ   ÚloggingZ
traits.apir   r   r   r   r   r   Ú	getLoggerr   r4   r   r   r   r   r   Ú<module>   s    
