U
    Mh                     @   sX   d dl Zd dlmZ d dlmZ d dlZd dlmZ dZG dd dZ	G dd	 d	Z
dS )
    N)glob)cast)Storagez.data/serialization_idc                   @   s   e Zd Zdd Zdd ZdS )_HasStoragec                 C   s
   || _ d S NZ_storage)selfstorage r
   Q/var/www/html/venv/lib/python3.8/site-packages/torch/package/_directory_reader.py__init__   s    z_HasStorage.__init__c                 C   s   | j S r   r   r   r
   r
   r   r	      s    z_HasStorage.storageN)__name__
__module____qualname__r   r	   r
   r
   r
   r   r      s   r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )DirectoryReaderar  
    Class to allow PackageImporter to operate on unzipped packages. Methods
    copy the behavior of the internal PyTorchFileReader class (which is used for
    accessing packages in all other cases).

    N.B.: ScriptObjects are not depickleable or accessible via this DirectoryReader
    class due to ScriptObjects requiring an actual PyTorchFileReader instance.
    c                 C   s
   || _ d S r   )	directory)r   r   r
   r
   r   r      s    zDirectoryReader.__init__c              
   C   s:   | j  d| }t|d}| W  5 Q R  S Q R X d S )N/rb)r   openread)r   namefilenamefr
   r
   r   
get_record"   s    zDirectoryReader.get_recordc                 C   s>   | j  d| }tj|| }tttj}t|j||dS )Nr   )r   nbytes)	r   torchZ_utilsZ_element_sizer   r   ZUntypedStorager   	from_file)r   r   ZnumelZdtyper   r   r	   r
   r
   r   get_storage_from_record'   s    z'DirectoryReader.get_storage_from_recordc                 C   s   t j| j|}t j|S r   )ospathjoinr   isfile)r   r    	full_pathr
   r
   r   
has_record-   s    zDirectoryReader.has_recordc                 C   sJ   g }t | j dddD ],}tj|s||t| jd d   q|S )Nz/**T)	recursive   )r   r   r   r    isdirappendlen)r   filesr   r
   r
   r   get_all_records1   s
    zDirectoryReader.get_all_recordsc                 C   s   |  tr| tS dS d S )N )r$    __serialization_id_record_name__r   r   r
   r
   r   serialization_id:   s    

z DirectoryReader.serialization_idN)
r   r   r   __doc__r   r   r   r$   r+   r.   r
   r
   r
   r   r      s   		r   )os.pathr   r   typingr   r   Ztorch.typesr   r-   r   r   r
   r
   r
   r   <module>   s   