o
    ADiC1                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dl	mZ d d	l	mZ d d
l	mZ dgZdddZdddZG dd dZdS )    )annotationsN)datetime)S_IFDIR)S_IFLNK)S_IFREG)Any)Iterator)Mapping)SequenceUPathStatResultvaluer   returnint | floatc                 C  s   t | ttfr	| S t | tr"| dr| dd d } t|  S t | tr+|  S tj	d| dt
| dtdd	 td| d
)z4Try to convert a datetime-like value to a timestamp.ZNz+00:00zCannot convert z	 of type zW to a timestamp. Please report this at: https://github.com/fsspec/universal_path/issues   
stacklevelz to a timestamp.)
isinstanceintfloatstrendswithr   fromisoformat	timestampwarningswarntypeRuntimeWarning	TypeError)r    r    D/var/www/Datamplify/venv/lib/python3.10/site-packages/upath/_stat.py_convert_value_to_timestamp   s   


r"   tuple[str, ...]c                  C  sN   t tt jj} |  }t|tsJ d|\}\}}t||jd}t|S )z6retrieve the extra fields of the os.stat_result class.z+unexpected return os.stat_result.__reduce__)key)	osstat_resultrangen_fields
__reduce__r   tuplesorted__getitem__)srrd_extraextra_fieldsr    r    r!   _get_stat_result_extra_fields'   s   r2   c                   @  s  e Zd ZdZdZdZe ZeeZ	eeee Z
eeeeZe
ejj
ks4e	ejj	ks4eejjkrHejdededejj
 dedd 		dSdTddZdd Zdd ZedUddZdVddZedWddZedWdd ZedWd!d"ZedWd#d$ZedWd%d&ZedWd'd(ZedWd)d*Z edXd,d-Z!edXd.d/Z"edXd0d1Z#edXd2d3Z$d4d5 Z%dWd6d7Z&dYd9d:Z'dZd[d@dAZ(d\dBdCZ)d]dGdHZ*dIdJ Z+dKdL Z,dMdN Z-dSdOdPZ.dQdR Z/d	S )^r   a  A stat_result compatible class wrapping fsspec info dicts.

    **Note**: It is unlikely that you will ever have to instantiate
      this class directly. If you want to convert and info dict,
      use: `UPathStatResult.from_info(info)`

    This object may be accessed either as a tuple of
      (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
    or via the attributes st_mode, st_ino, st_dev, st_nlink, st_uid, and so on.

    There's an additional method `as_info()` for accessing the info dict.
    This is useful to access additional information provided by the file system
    implementation, that's not covered by the stat_result tuple.

    )_seq_info)
st_modest_inost_devst_nlinkst_uidst_gidst_sizest_atimest_mtimest_ctimez]UPathStatResult: The assumed number of fields in the stat_result class is not correct. Got:  , zh This might cause problems? Please report this issue at: https://github.com/fsspec/universal_path/issuesr   r   Nstat_result_seqSequence[int]	info_dictMapping[str, Any] | Noner   Nonec                 C  s   t |}t|| jk  }rt| j d| j d|| jkr*t| j d| j d| j|  kr6| jk rEn ntjd| j dtdd |d| j | _	|pPi | _
dS )	z~init compatible with os.stat_result

        Use `UPathStatResult.from_info(info)` to instantiate from a fsspec info.
        z takes at least z-sequence ({n}-sequence given)z takes at most z,UPathStatResult: The seq provided more than z# items. Ignoring the extra items...r   r   N)r*   lenn_sequence_fieldsr   __name__r(   r   r   UserWarningr3   r4   )selfr@   rB   seqnr    r    r!   __init__n   s&   	
zUPathStatResult.__init__c                 C  s<   t | j}dtdjt| j| }| d| d| jdS )Nr?   z{0[0]}={0[1]}(z, info=))r   rG   joinmapformatzip_fieldsr4   )rI   cls_name	seq_attrsr    r    r!   __repr__   s   
zUPathStatResult.__repr__c                 C  s   t |tstS | j|jkS N)r   r   NotImplementedr4   )rI   otherr    r    r!   __eq__   s   
zUPathStatResult.__eq__infoMapping[str, Any]c                 C  s   dg| j  }| ||S )z1Create a UPathStatResult from a fsspec info dict.r   )rF   )clsr[   defaultsr    r    r!   	from_info   s   
zUPathStatResult.from_infoc                 C  s   | j S )zReturn the fsspec info dict.)r4   rI   r    r    r!   as_info   s   zUPathStatResult.as_infor   c                 C  s   | j d}t|tr|S t|tr"zt|dW S  ty!   Y nw | j d}|dkr.tS |dkr4tS | j dr<tS | j	d S )zprotection bitsmode   r   file	directoryisLinkr   )
r4   getr   r   r   
ValueErrorr   r   r   r3   )rI   rb   type_r    r    r!   r5      s"   


zUPathStatResult.st_modec                 C  $   | j d}t|tr|S | jd S )inodeino   r4   rg   r   r   r3   )rI   rl   r    r    r!   r6         

zUPathStatResult.st_inoc                 C  rj   )devicedevr   rn   )rI   rq   r    r    r!   r7      ro   zUPathStatResult.st_devc                 C  rj   )znumber of hard linksnlink   rn   )rI   rr   r    r    r!   r8      ro   zUPathStatResult.st_nlinkc                 C  @   dD ]}z
t | j| W   S  tttfy   Y qw | jd S )zuser ID of owner)uidownerunamez
unix.owner   r   r4   rh   r   KeyErrorr3   rI   r$   r    r    r!   r9         
zUPathStatResult.st_uidc                 C  rt   )zgroup ID of owner)gidgroupgnamez
unix.group   ry   r{   r    r    r!   r:      r|   zUPathStatResult.st_gidc              
   C  s4   zt | jd W S  tttfy   | jd  Y S w )ztotal size, in bytessize   ry   r`   r    r    r!   r;      s
   zUPathStatResult.st_sizer   c              
   C  Z   dD ]%}z| j | }W n	 ty   Y qw zt|W   S  ttfy'   Y qw | jd S )ztime of last access)atimetimelast_accessed
accessTime   r4   rz   r"   r   rh   r3   rI   r$   	raw_valuer    r    r!   r<      s   
zUPathStatResult.st_atimec              
   C  r   )ztime of last modification)mtimeLastModifiedlast_modifiedtimeModifiedmodificationTimemodified_atrc   r   r   r    r    r!   r=      s   
zUPathStatResult.st_mtimec              	   C  sN   z| j d }W n	 ty   Y nw zt|W S  ttfy!   Y nw | jd S )ztime of last changectime	   r   )rI   r   r    r    r!   r>     s   

zUPathStatResult.st_ctimec              
   C  sX   dD ]%}z| j | }W n	 ty   Y qw zt|W   S  ttfy'   Y qw td)ztime of creation)	birthtimecreatedcreation_timetimeCreated
created_atr   )r4   rz   r"   r   rh   AttributeErrorr   r    r    r!   st_birthtime"  s   zUPathStatResult.st_birthtimec                 C  s   || j v rdS t|)Nr   )_fields_extrar   )rI   itemr    r    r!   __getattr__8  s   
zUPathStatResult.__getattr__c                 C  s
   t | jS rW   )rE   rS   r`   r    r    r!   __len__?  s   
zUPathStatResult.__len__Iterator[int]c                 c  s"    | j D ]
}tt| |V  qdS )zfthe sequence interface iterates over the guaranteed fields.

        All values are integers.
        N)rS   r   getattr)rI   fieldr    r    r!   __iter__B  s   
zUPathStatResult.__iter__r   r   startstop
int | Nonec                C  s"   |du r	t | j}| j|||S )z$the sequence interface index method.N)rE   r3   index)rI   r   r   r   r    r    r!   r   J  s   
zUPathStatResult.indexc                 C  s   | j |S )z$the sequence interface count method.)r3   count)rI   r   r    r    r!   r   P  s   zUPathStatResult.countr   	int | strr   c                 C  s<   t |trtjdtdd | j| S | j| }tt| |S )Nz,Access the fsspec info via `.as_info()[key]`r   r   )	r   r   r   r   DeprecationWarningr4   rS   r   r   )rI   r   attrr    r    r!   r,   V  s   


zUPathStatResult.__getitem__c                 C     t jdtdd | j S )2compatibility with the fsspec info dict interface.z.Access the fsspec info via `.as_info().keys()`r   r   )r   r   r   r4   keysr`   r    r    r!   r   b     
zUPathStatResult.keysc                 C  r   )r   z0Access the fsspec info via `.as_info().values()`r   r   )r   r   r   r4   valuesr`   r    r    r!   r   k  r   zUPathStatResult.valuesc                 C  r   )r   z/Access the fsspec info via `.as_info().items()`r   r   )r   r   r   r4   itemsr`   r    r    r!   r   t  r   zUPathStatResult.itemsc                 C  s   t jdtdd | j||S )r   z9Access the fsspec info via `.as_info().get(key, default)`r   r   )r   r   r   r4   rg   )rI   r$   defaultr    r    r!   rg   }  s   zUPathStatResult.getc                 C  r   )r   z.Access the fsspec info via `.as_info().copy()`r   r   )r   r   r   r4   copyr`   r    r    r!   r     r   zUPathStatResult.copyrW   )r@   rA   rB   rC   r   rD   )r[   r\   r   r   )r   r\   )r   r   )r   r   )r   r   )r   N)r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )0rG   
__module____qualname____doc__	__slots__rS   r2   r   rE   rF   r(   setintersectionn_unnamed_fieldsr%   r&   r   r   r   rL   rV   rZ   classmethodr_   ra   propertyr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r   r   r   r   r   r   r,   r   r   r   rg   r   r    r    r    r!   r   5   s|    
		



		
		)r   r   r   r   )r   r#   )
__future__r   r%   r   r   statr   r   r   typingr   r   r	   r
   __all__r"   r2   r   r    r    r    r!   <module>   s     

