o
    wZh{                     @   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   
   || _ d S NZ_storage)selfstorage r   N/var/www/auris/lib/python3.10/site-packages/torch/package/_directory_reader.py__init__      
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   r   r   )	directory)r	   r   r   r   r   r       r   zDirectoryReader.__init__c                 C   sF   | j  d| }t|d}| W  d    S 1 sw   Y  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   torch_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                    s&    fddt  j dddD }|S )Nc                    s.   g | ]}t j|s|t jd  d qS )   N)r"   r#   isdirlenr   ).0r   r   r   r   
<listcomp>5   s    
z3DirectoryReader.get_all_records.<locals>.<listcomp>z/**T)	recursive)r   r   )r	   filesr   r   r   get_all_records2   s   
zDirectoryReader.get_all_recordsc                 C   s   |  tr
| t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/   r2   r   r   r   r   r      s    	
r   )Zos.pathr"   r   typingr   r   Ztorch.typesr   r1   r   r   r   r   r   r   <module>   s   