
    i                         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
      Zdede
fdZ G d de j6                  e	e         Zy)    N)Path)TemporaryDirectory)GenericCallableIterableOptionalTupleTypeVarUnion   )CloudImplementation	CloudPathimplementation_registry)FileCacheMode)InvalidConfigurationExceptionBoundedCloudPath)boundkeyreturnc                 ,     dt         dt         f fd}|S )Nclsr   c                     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   s    d/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/cloudpathlib/client.py	decoratorz(register_client_class.<locals>.decorator   sF    #v&JKK58$2,/$)1#6
    )type)r   r    s   ` r   register_client_classr#      s    t   r!   c            
          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ZddZed d	       Zdd
Zde	e
ef   de
defdZd Zej0                  dede	e
ej                  f   defd       Zej0                  dedefd       Zej0                  dededeeeef      fd       Zej0                  	 d!dedededefd       Z ej0                  d!dededdfd       Z!ej0                  de	e
ej                  f   dedefd       Z"ej0                  dede
fd       Z#ej0                  	 d"dede$de
fd       Z%y)#r   r   Nfile_cache_modelocal_cache_dircontent_type_methodc                 f   d | _         d | _        | j                  j                          t	        |t
              rt        |      }|t        j                         }|'t        j                  j                  dd       }|dk(  rd }|r|t        j                  }|t        j                  k(  r|t        dt        j                   d      |7t               | _        | j                  j                  }|t        j                  }t!        |      | _        || _        |t        j                  }|| _         y )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'   s       r   __init__zClient.__init__!   s0     $"..0 os++O<O "+<<>O" jjnn-KTRO "$"& 6+66Om666?;R/"=#;#;"<  =M  N 
 ""4"6D"1166O&"/"7"7 $_ 5#6  "+33O.r!   r   c                    t        | dd       t        j                  t        j                  t        j                  fv rF| j                          | j                  j                         r| j                  j                          y y y )Nr%   )	getattrr   r4   
close_filecloudpath_objectclear_cacher5   existsrmdirr6   s    r   __del__zClient.__del__U   sr     4*D1!!$$**6
 

 $$++-%%++- .
r!   c                 J    | j                    |        | _         | 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.
        )_default_client)r   s    r   get_default_clientzClient.get_default_clientb   s&    
 &"%%C"""r!   c                 &    | | j                   _        y)zSet this client instance as the default one used when instantiating cloud path
        instances for this cloud without a client specified.N)	__class__rB   r?   s    r   set_as_default_clientzClient.set_as_default_clientk   s     *.&r!   
cloud_pathpartsc                 B     | j                   j                  |g|d| iS )Nclient)r   
path_class)r6   rG   rH   s      r   r   zClient.CloudPathp   s%    *t**:KKdKKr!   c                     | j                   j                         rV| j                   j                         D ]8  }|j                         r|j	                          $t        j                  |       : yy)zqClears the contents of the cache folder.
        Does not remove folder so it can keep being written to.
        N)r5   r=   iterdiris_fileunlinkshutilrmtree)r6   ps     r   r<   zClient.clear_caches   sW       '')**224 %99;HHJMM!$	% *r!   
local_pathc                      y N )r6   rG   rS   s      r   _download_filezClient._download_file~        	r!   c                      y rU   rV   r6   rG   s     r   _existszClient._exists       r!   	recursivec                      y)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.
        NrV   )r6   rG   r]   s      r   	_list_dirzClient._list_dir   s    $ 	r!   srcdst
remove_srcc                      y rU   rV   )r6   r`   ra   rb   s       r   
_move_filezClient._move_file   rX   r!   path
missing_okc                      y)zRemove a file or folder from the server.

        Parameters
        ----------
        path : CloudPath
            The file or folder to remove.
        NrV   )r6   re   rf   s      r   _removezClient._remove   s     	r!   c                      y rU   rV   )r6   rS   rG   s      r   _upload_filezClient._upload_file   rX   r!   c                      y rU   rV   rZ   s     r   _get_public_urlzClient._get_public_url   r\   r!   expire_secondsc                      y rU   rV   )r6   rG   rm   s      r   _generate_presigned_urlzClient._generate_presigned_url   rX   r!   )r   N)r   r   )T)i  )&__name__
__module____qualname__r   __annotations__rB   	mimetypes
guess_typer   r   r.   r   r0   PathLiker   r7   r@   classmethodrC   rF   r   r   r<   abcabstractmethodr   rW   boolr[   r   r	   r_   rd   rh   rj   rl   intro   rV   r!   r   r   r      sl   $$O @D=A2;2F2F	2/!%](:";<2/ "%R[[(8"9:2/ &h/	2/h. # #.
LE#/?*?$@ L# LRb L	% 	*8=c2;;>N8O	 
 	"2 t   	*7;	%($./	0 & 	OS#*:HL	 
 	, $ $   	R[[ 01?O	 
 	*: s   	BI*<?	 r!   r   )rx   rt   r0   pathlibr   rP   tempfiler   typingr   r   r   r   r	   r
   r   	cloudpathr   r   r   enumsr   
exceptionsr   r   r.   r#   ABCr   rV   r!   r   <module>r      si    
  	   ' O O O N N   5 -Y? 	s 	x 	^SWWg./ ^r!   