
    sg                     d    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      Z	 G d d	      Z
y)
    N)glob)cast)Storagez.data/serialization_idc                       e Zd Zd Zd Zy)_HasStoragec                     || _         y N_storage)selfstorages     R/var/www/html/venv/lib/python3.12/site-packages/torch/package/_directory_reader.py__init__z_HasStorage.__init__   s	        c                     | j                   S r	   r
   r   s    r   r   z_HasStorage.storage   s    }}r   N)__name__
__module____qualname__r   r    r   r   r   r      s     r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	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                     || _         y r	   )	directory)r   r   s     r   r   zDirectoryReader.__init__    s	    "r   c                     | j                    d| }t        |d      5 }|j                         cd d d        S # 1 sw Y   y xY w)N/rb)r   openread)r   namefilenamefs       r   
get_recordzDirectoryReader.get_record#   sA    nn%Qtf-(D! 	Q668	 	 	s	   8Ac                     | j                    d| }t        j                  j                  |      |z  }t	        t
        t        j                        }t        |j                  ||            S )Nr   )r!   nbytes)	r   torch_utils_element_sizer   r   UntypedStorager   	from_file)r   r    numeldtyper!   r%   r   s          r   get_storage_from_recordz'DirectoryReader.get_storage_from_record(   s]    nn%Qtf-++E2U:w 4 457,,hv,NOOr   c                     t         j                  j                  | j                  |      }t         j                  j	                  |      S r	   )ospathjoinr   isfile)r   r0   	full_paths      r   
has_recordzDirectoryReader.has_record.   s-    GGLL6	ww~~i((r   c                     g }t        | j                   dd      D ]L  }t        j                  j	                  |      r#|j                  |t        | j                        dz   d         N |S )Nz/**T)	recursive   )r   r   r/   r0   isdirappendlen)r   filesr!   s      r   get_all_recordszDirectoryReader.get_all_records2   sf     /s3tD 	BH77==*Xc$..&9A&=&?@A	B r   c                 X    | j                  t              r| j                  t              S y)N )r4    __serialization_id_record_name__r#   r   s    r   serialization_idz DirectoryReader.serialization_id;   s$     ??;<??#CDDr   N)
r   r   r   __doc__r   r#   r-   r4   r<   r@   r   r   r   r   r      s&    #
P)r   r   )os.pathr/   r   typingr   r&   torch.typesr   r?   r   r   r   r   r   <module>rE      s0         $<   + +r   