o
    oĎi                     @   s   d dl Z d dlZd dlZd dlmZ d dlZd dlmZ d dlm	Z	m
Z
mZmZmZmZmZ ddlmZmZmZ ddlmZ ddlmZ ed	ed
Zdede
fddZG dd de je	e ZdS )    N)Path)TemporaryDirectory)GenericCallableIterableOptionalTupleTypeVarUnion   )CloudImplementation	CloudPathimplementation_registry)FileCacheMode)InvalidConfigurationExceptionBoundedCloudPath)boundkeyreturnc                    s   dt dt f fdd}|S )Nclsr   c                    s4   t | ts	td| t  _ t  _t  | _| S )Nz,Only subclasses of Client can be registered.)
issubclassClient	TypeErrorr   _client_classname_cloud_metar   r    O/home/jeff/fluffinator/venv/lib/python3.10/site-packages/cloudpathlib/client.py	decorator   s   



z(register_client_class.<locals>.decorator)type)r   r    r   r   r   register_client_class   s   r"   c                
   @   s  e Zd ZU eed< dZddejfdee	e
ef  dee	e
ejf  dee fddZd/d	d
Zed0ddZd/ddZde	e
ef de
defddZdd Zejdede	e
ejf defddZejdedefddZejdededeeeef  fddZej	d1deded edefd!d"Z ejd1d#ed$eddfd%d&Z!ejde	e
ejf dedefd'd(Z"ejdede
fd)d*Z#ej	+d2ded,e$de
fd-d.Z%dS )3r   r   Nfile_cache_modelocal_cache_dircontent_type_methodc                 C   s   d | _ d | _| j  t|trt|}|d u rt }|d u r-tj	
dd }|dkr-d }|r6|d u r6tj}|tjkrH|d u rHtdtj d|d u r[t | _| jj}|d u r[tj}t|| _|| _|d u rjtj}|| _ d S )NCLOUDPATHLIB_LOCAL_CACHE_DIR zIf you use the 'zP' cache mode, you must pass a `local_cache_dir` when you instantiate the client.)r#   _cache_tmp_dirr   validate_completeness
isinstancestrr   from_environmentosenvironget
persistentr   r   r   tmp_dirr   _local_cache_dirr%   )selfr#   r$   r%   r   r   r   __init__!   s6   



zClient.__init__r   c                 C   sD   t | dd tjtjtjfv r|   | j r | j  d S d S d S )Nr#   )	getattrr   r1   
close_filecloudpath_objectclear_cacher2   existsrmdirr3   r   r   r   __del__U   s   

zClient.__del__c                 C   s   | j du r	|  | _ | j S )zGet the default client, which the one that is used when instantiating a cloud path
        instance for this cloud without a client specified.
        N)_default_clientr   r   r   r   get_default_clientb   s   
zClient.get_default_clientc                 C   s   | | j _dS )zSet this client instance as the default one used when instantiating cloud path
        instances for this cloud without a client specified.N)	__class__r=   r;   r   r   r   set_as_default_clientk   s   zClient.set_as_default_client
cloud_pathpartsc                 G   s   | j j|g|R d| iS )Nclient)r   
path_class)r3   rA   rB   r   r   r   r   p   s   zClient.CloudPathc                 C   s>   | j  r| j  D ]}| r|  q
t| q
dS dS )zqClears the contents of the cache folder.
        Does not remove folder so it can keep being written to.
        N)r2   r9   iterdiris_fileunlinkshutilrmtree)r3   pr   r   r   r8   s   s   

zClient.clear_cache
local_pathc                 C      d S Nr   )r3   rA   rK   r   r   r   _download_file~      zClient._download_filec                 C   rL   rM   r   r3   rA   r   r   r   _exists      zClient._exists	recursivec                 C      dS )a  List all the files and folders in a directory.

        Parameters
        ----------
        cloud_path : CloudPath
            The folder to start from.
        recursive : bool
            Whether or not to list recursively.

        Returns
        -------
        contents : Iterable[Tuple]
            Of the form [(CloudPath, is_dir), ...] for every child of the dir.
        Nr   )r3   rA   rS   r   r   r   	_list_dir   s   zClient._list_dirTsrcdst
remove_srcc                 C   rL   rM   r   )r3   rV   rW   rX   r   r   r   
_move_file   rO   zClient._move_filepath
missing_okc                 C   rT   )zRemove a file or folder from the server.

        Parameters
        ----------
        path : CloudPath
            The file or folder to remove.
        Nr   )r3   rZ   r[   r   r   r   _remove   s   	zClient._removec                 C   rL   rM   r   )r3   rK   rA   r   r   r   _upload_file   rO   zClient._upload_filec                 C   rL   rM   r   rP   r   r   r   _get_public_url   rR   zClient._get_public_url  expire_secondsc                 C   rL   rM   r   )r3   rA   r`   r   r   r   _generate_presigned_url   rO   zClient._generate_presigned_url)r   N)r   r   )T)r_   )&__name__
__module____qualname__r   __annotations__r=   	mimetypes
guess_typer   r
   r+   r   r-   PathLiker   r4   r<   classmethodr>   r@   r   r   r8   abcabstractmethodr   rN   boolrQ   r   r   rU   rY   r\   r]   r^   intra   r   r   r   r   r      s   
 

4

r   )rj   rf   r-   pathlibr   rH   tempfiler   typingr   r   r   r   r   r	   r
   	cloudpathr   r   r   enumsr   
exceptionsr   r   r+   r"   ABCr   r   r   r   r   <module>   s    $