U
    ‰dÅ  ã                   @   s2   d dl Z d dlZddlmZ G dd„ dejƒZdS )é    Né   )ÚImporterc                       s.   e Zd ZdZedœ‡ fdd„Zdd„ Z‡  ZS )ÚPackageUnpicklerz«Package-aware unpickler.

    This behaves the same as a normal unpickler, except it uses `importer` to
    find any global names that it encounters while unpickling.
    )Úimporterc                    s   t ƒ j||Ž || _d S )N)ÚsuperÚ__init__Ú	_importer)Úselfr   ÚargsÚkwargs©Ú	__class__© úD/tmp/pip-unpacked-wheel-ua33x9lu/torch/package/_package_unpickler.pyr      s    zPackageUnpickler.__init__c                 C   s\   | j dk rF| jrF||ftjkr2tj||f \}}n|tjkrFtj| }| j |¡}t||ƒS )Né   )ÚprotoÚfix_importsÚ_compat_pickleÚNAME_MAPPINGÚIMPORT_MAPPINGr   Úimport_moduleÚgetattr)r	   ÚmoduleÚnameÚmodr   r   r   Ú
find_class   s    

zPackageUnpickler.find_class)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__classcell__r   r   r   r   r      s   r   )r   Úpickler   r   Ú
_Unpicklerr   r   r   r   r   Ú<module>   s   