o
    oĎiw                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
 zd dlmZ W n	 ey1   Y nw ddlmZmZmZ erDd	d
lmZ edG dd deZdS )    N)Path)TemporaryDirectory)AnyOptionalTYPE_CHECKING)CloudPathIsADirectoryError)ResourceNotFoundError   )	CloudPathNoStatErrorregister_path_class   )AzureBlobClientazurec                       s   e Zd ZU dZdZeed< ded< edefddZdde	e
 fddZd dede	e
 fddZd!ddZd" fddZedefddZedefddZedd ZedefddZ  ZS )#AzureBlobPathaj  Class for representing and operating on Azure Blob Storage URIs, in the style of the Python
    standard library's [`pathlib` module](https://docs.python.org/3/library/pathlib.html).
    Instances represent a path in Blob Storage with filesystem path semantics, and convenient
    methods allow for basic operations like joining, reading, writing, iterating over contents,
    etc. This class almost entirely mimics the [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
    interface, so most familiar properties and methods should be available and behave in the
    expected way.

    The [`AzureBlobClient`](../azblobclient/) class handles authentication with Azure. If a
    client instance is not explicitly specified on `AzureBlobPath` instantiation, a default client
    is used. See `AzureBlobClient`'s documentation for more details.
    zaz://cloud_prefixr   clientreturnc                 C   s   | j S N)	containerself r   Y/home/jeff/fluffinator/venv/lib/python3.10/site-packages/cloudpathlib/azure/azblobpath.pydrive&   s   zAzureBlobPath.driveFNmodec                 C   s   | j j| ||d d S )N)parentsexist_ok)r   _mkdir)r   r   r   r   r   r   r   mkdir*   s   zAzureBlobPath.mkdirTr   c                 C   sb   |   r|std|  | j| |  d S t }t|jd }|  | j||  |	  d S )NzFile exists: empty)
existsFileExistsErrorr   
_move_filer   r   nametouch_upload_filecleanup)r   r   r   tfpr   r   r   r%   -   s   zAzureBlobPath.touchc                 C   sd   z| j | }W n ty   td|  dw td d | jd d d |ddd |dd d f
S )NzNo stats available for z%; it may be a directory or not exist.sizer   last_modified)	r   _get_metadatar   r   osstat_resultr   get	timestamp)r   follow_symlinksmetar   r   r   stat;   s(   

zAzureBlobPath.stattargetc                    s>   zt  |W S  ty   | j| r| j| | Y S  w r   )superreplacer   r   
_check_hnsr#   )r   r4   	__class__r   r   r6   R   s   zAzureBlobPath.replacec                 C   s   | j ddd S )N/r   r   )
_no_prefixsplitr   r   r   r   r   ]   s   zAzureBlobPath.containerc                 C   s    | j }|dr|dd  }|S )Nr:   r   )_no_prefix_no_drive
startswith)r   keyr   r   r   bloba   s   
zAzureBlobPath.blobc                 C   s   | j | dd S )Netagr   r,   r/   r   r   r   r   rA   k   s   zAzureBlobPath.etagc                 C   s   | j | di dd S )Ncontent_settingscontent_md5rB   r   r   r   r   md5o   s   zAzureBlobPath.md5)FFN)TN)T)r4   r   r   r   )__name__
__module____qualname____doc__r   str__annotations__propertyr   r   r   r   boolr%   r3   r6   r   r@   rA   rE   __classcell__r   r   r8   r   r      s$   
 
	
r   )r-   pathlibr   tempfiler   typingr   r   r   cloudpathlib.exceptionsr   azure.core.exceptionsr   ImportError	cloudpathr
   r   r   azblobclientr   r   r   r   r   r   <module>   s    