
    R}bg6                         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 d
lmZ d dlmZ n# e$ r  ed          w xY we G d de
                      Z G d de          ZdS )    N)urljoin)settings)ImproperlyConfigured)File)Storage)deconstructible)
clean_name)
get_driver)ObjectDoesNotExistError)ProviderzCould not load libcloudc                   Z    e Zd ZdZddZd Zd Zd Zd Zdd	Z	d
 Z
d ZddZd Zd ZdS )LibCloudStoragezXDjango storage derived class using apache libcloud to operate
    on supported providersNc                    |t          t          dd          }t          j                            |          | _        | j        st          d|z            i }d| j        v r| j        d         |d<   d| j        v r| j        d         |d<   	 | j        d         }t          |t                    rC|                    dd          \  }}|d	k    rt          d
          t          t          |          }t          |          } || j        d         | j        d         fi || _        n?# t          $ r2}t          d| j                            d          d|          d }~ww xY w| j        d         | _        d S )NDEFAULT_LIBCLOUD_PROVIDERdefaultz,LIBCLOUD_PROVIDERS %s not defined or invalidregionprojecttype.   zlibcloud.storage.types.ProviderzInvalid module pathuserkeyz&Unable to create libcloud driver type z: bucket)getattrr   LIBCLOUD_PROVIDERSgetproviderr   
isinstancestrrsplit
ValueErrorr   r
   driver	Exceptionr   )	selfprovider_nameoptionextra_kwargsprovider_typemodule_pathtagDriveres	            t/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/storages/backends/apache_libcloud.py__init__zLibCloudStorage.__init__   s    #H.I9UUM 377FF} 	&>N   t}$$%)]8%<L"%%&*mI&>L#	 M&1M--- 7#0#7#7Q#?#? S"CCC$%:;;; '# 6 6..F &f%t}U'; ?K DKK  	 	 	&&=$$V,,,,aa1  	
 mH-s   BD% %
E!/-EE!c                 @    | j                             | j                  S )z0Helper to get bucket object (libcloud container))r"   get_containerr   r$   s    r-   _get_bucketzLibCloudStorage._get_bucket>   s    {((555    c                 \    | j                             | j        t          |                    S )zZGet object by its name. ObjectDoesNotExistError will be raised if object not
        found)r"   
get_objectr   r	   )r$   names     r-   _get_objectzLibCloudStorage._get_objectB   s&     {%%dk:d3C3CDDDr3   c                     	 |                      |          }| j                            |          S # t          $ r Y dS w xY w)zDelete object on remoteN)r7   r"   delete_objectr   r$   r6   objs      r-   deletezLibCloudStorage.deleteG   sR    	""4((C;,,S111& 	 	 	DD	s   .1 
??c                 V    	 |                      |          }n# t          $ r Y dS w xY wdS )NFT)r7   r   )r$   r6   _s      r-   existszLibCloudStorage.existsO   sC    	  &&AA& 	 	 	55	ts    
&&/c                    |                                  }| j                            |          }t          |          }|                    d          sd|z  }g }g }|D ]t}|dk    r|j                            d          dk    r|                    |j                   B|j                            d          dk    r@|j        d|j                            d                   }||vr|                    |           |j        	                    |          r|j                            d          |                    d          k    r|j                            d          r=|j        dd         }|t          |          d         }|                    |           C|j        t          |          d         }|                    |           v||fS )zLists the contents of the specified path,
        returning a 2-tuple of lists; the first item being
        directories, the second item being files.
        r@   z%s/r   r   Nz	_$folder$i)r2   r"   list_container_objectsr	   endswithr6   countappendindex
startswithlen)	r$   path	containerobjectsfilesdirsodir_namer6   s	            r-   listdirzLibCloudStorage.listdirV   s   
 $$&&	+44Y??$}}S!! 	 4<D  	+ 	+As{{6<<$$))LL((((V\\#&&!++ v&9S(9(9&9:Ht++H---""4(( 	+6<<$$

377v{33 + vcrc{#CIIKK0D)))) vc$iikk2T***e}r3   c                 B    |                      |          }|r|j        ndS )N)r7   sizer:   s      r-   rS   zLibCloudStorage.sizex   s&    t$$&sxxB&r3   c                    | j         d                                         }|                     |          }|sd S 	 | j                            |          }n# t
          $ r}d                    | j        |j                  }d|v r%d| j        j	        j
        z  }t          ||          }nQd|v rt          d|          }n<d|v r!d| j         d	         z  }t          ||          }nd
|v rt          d|          }n|Y d }~nd }~ww xY w|S )Nr   z{}/{}s3z
https://%sgooglezhttps://storage.googleapis.comazurez https://%s.blob.core.windows.netr   	backblazezapi.backblaze.com/b2api/v1/)r   lowerr7   r"   get_object_cdn_urlNotImplementedErrorformatr   r6   
connectionhostr   )r$   r6   r(   r;   urlr,   object_pathbase_urls           r-   r_   zLibCloudStorage.url|   s2   f-3355t$$ 	4	+0055CC" 	 	 	!..ch??K}$$'$+*@*EEh44]**>LLM))=f@UUh44--;[II	 
s   A 
DBC>>Drbc                 *    t          || |          }|S )N)mode)LibCloudFile)r$   r6   rd   remote_files       r-   _openzLibCloudStorage._open   s    "4D999r3   c                     	 |                      |          }n.# t          $ r!}t          t          |                    d }~ww xY wt	          | j                            ||j                            S N)r7   r   FileNotFoundErrorr   nextr"   download_object_as_streamrS   )r$   r6   r;   r,   s       r-   _readzLibCloudStorage._read   ss    	,""4((CC& 	, 	, 	,#CFF+++	, DK99#sxHHIIIs    
A>Ac                 |    | j                             t          |          |                                 |           |S ri   )r"   upload_object_via_streamiterr2   )r$   r6   files      r-   _savezLibCloudStorage._save   s3    ,,T$ZZ9I9I9K9KTRRRr3   )NN)r@   )rb   )__name__
__module____qualname____doc__r.   r2   r7   r<   r?   rP   rS   r_   rg   rm   rr    r3   r-   r   r      s          .  .  .  .D6 6 6E E E
           D' ' '  .   J J J    r3   r   c                   f    e Zd ZdZd Zd Zd Z eee          Zed             Z	d
dZ
d Zd	 ZdS )re   z@File inherited class for libcloud storage objects read and writec                 L    || _         || _        || _        d| _        d | _        d S )NF)r6   _storage_mode	_is_dirty_file)r$   r6   storagerd   s       r-   r.   zLibCloudFile.__init__   s)    	



r3   c                     | j         8| j                            | j                  }t	          j        |          | _         | j         S ri   )r}   rz   rm   r6   ioBytesIO)r$   datas     r-   	_get_filezLibCloudFile._get_file   s:    :=&&ty11DD))DJzr3   c                     || _         d S ri   )r}   )r$   values     r-   	_set_filezLibCloudFile._set_file   s    


r3   c                 x    t          | d          s$| j                            | j                  | _        | j        S )N_size)hasattrrz   rS   r6   r   r1   s    r-   rS   zLibCloudFile.size   s5    tW%% 	7++DI66DJzr3   Nc                 6    | j                             |          S ri   )rq   read)r$   	num_bytess     r-   r   zLibCloudFile.read   s    y~~i(((r3   c                 v    d| j         vrt          d          t          j        |          | _        d| _        d S )Nwz%File was opened for read-only access.T)r{   AttributeErrorr   r   rq   r|   )r$   contents     r-   writezLibCloudFile.write   s:    dj   !HIIIJw''	r3   c                     | j         r%| j                            | j        | j                   | j                                         d S ri   )r|   rz   rr   r6   rq   closer1   s    r-   r   zLibCloudFile.close   s@    > 	6M	49555	r3   ri   )rs   rt   ru   rv   r.   r   r   propertyrq   rS   r   r   r   rw   r3   r-   re   re      s        JJ       8Iy))D  X
) ) ) )      r3   re   )r   urllib.parser   django.confr   django.core.exceptionsr   django.core.files.baser   django.core.files.storager   django.utils.deconstructr   storages.utilsr	   libcloud.storage.providersr
   libcloud.storage.typesr   r   ImportErrorr   re   rw   r3   r-   <module>r      sl   
			                         7 7 7 7 7 7 ' ' ' ' ' ' - - - - - - 4 4 4 4 4 4 % % % % % %:555555>>>>>>/////// : : :

8
9
99: I I I I Ig I I IX' ' ' ' '4 ' ' ' ' 's   A A