o
    1jP                     @   sH  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZmZmZmZ d dlmZmZmZ ddlmZ g d	ZG d
d deZG dd deZG dd deZee
eeef edf ZeG dd de	ZG dd de jdZG dd deZG dd deZ edG dd deZ!dee"ef defdd Z#dS )!    N)PathLike)Path)AnyDictOptionalProtocolUnionruntime_checkable)	BaseModelDiscriminator	SecretStrTypeAdapter)	AnnotatedLiteralassert_never   )class_requires_deps)
InMemoryStorageConfigFileSystemStorageConfig	BOSConfigFileStorageConfigSupportsGetURLStorageInMemoryStorageFileSystemStorageBOScreate_storagec                   @   s   e Zd ZU dZed ed< dS )r   memorytypeN)__name__
__module____qualname__r   r   __annotations__ r#   r#   h/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/serving/infra/storage.pyr   '   s   
 r   c                   @   s.   e Zd ZU eeef ed< dZed ed< dS )r   	directoryfile_systemr   N)	r   r    r!   r   strr   r"   r   r   r#   r#   r#   r$   r   +   s   
 r   c                   @   s^   e Zd ZU eed< eed< eed< eed< dZee ed< dZee	 ed< dZ
ed ed	< dS )
r   endpointakskbucket_nameN
key_prefixconnection_timeout_in_millsbosr   )r   r    r!   r'   r"   r   r,   r   r-   intr   r   r#   r#   r#   r$   r   1   s   
 r   r   c                   @   s$   e Zd ZddededefddZdS )	r   key
expires_inreturnc                 C   s   d S Nr#   selfr1   r2   r#   r#   r$   get_urlD   s    zSupportsGetURL.get_urlNr0   )r   r    r!   r'   r/   r7   r#   r#   r#   r$   r   B   s    r   c                   @   sX   e Zd ZejdedefddZejdededdfddZejdeddfd	d
Z	dS )r   r1   r3   c                 C      t r4   NotImplementedErrorr6   r1   r#   r#   r$   getH      zStorage.getvalueNc                 C   r9   r4   r:   r6   r1   r?   r#   r#   r$   setL   r>   zStorage.setc                 C   r9   r4   r:   r<   r#   r#   r$   deleteP   r>   zStorage.delete)
r   r    r!   abcabstractmethodr'   bytesr=   rA   rB   r#   r#   r#   r$   r   G   s    r   )	metaclassc                       s`   e Zd Zdeddf fddZdedefddZded	eddfd
dZdeddfddZ	  Z
S )r   configr3   Nc                    s   t    i | _d S r4   )super__init___datar6   rG   	__class__r#   r$   rI   V   s   

zInMemoryStorage.__init__r1   c                 C   s
   | j | S r4   rJ   r<   r#   r#   r$   r=   Z      
zInMemoryStorage.getr?   c                 C   s   || j |< d S r4   rN   r@   r#   r#   r$   rA   ]   s   zInMemoryStorage.setc                 C   s   | j |= d S r4   rN   r<   r#   r#   r$   rB   `   s   zInMemoryStorage.delete)r   r    r!   r   rI   r'   rE   r=   rA   rB   __classcell__r#   r#   rL   r$   r   U   s
    r   c                       sr   e Zd Zdeddf fddZdedefddZded	eddfd
dZdeddfddZ	dede
fddZ  ZS )r   rG   r3   Nc                    s(   t    t|j| _| jjdd d S )NTexist_ok)rH   rI   r   r%   
_directorymkdirrK   rL   r#   r$   rI   e   s   
zFileSystemStorage.__init__r1   c                 C   s>   t | |d}| }W d    |S 1 sw   Y  |S )Nrb)open_get_file_pathread)r6   r1   fcontentsr#   r#   r$   r=   j   s   

zFileSystemStorage.getr?   c                 C   sR   |  |}|jjdd t|d}|| W d    d S 1 s"w   Y  d S )NTrQ   wb)rW   parentrT   rV   write)r6   r1   r?   pathrY   r#   r#   r$   rA   o   s
   
"zFileSystemStorage.setc                 C   s   |  |}|jdd d S )NT)
missing_ok)rW   unlink)r6   r1   	file_pathr#   r#   r$   rB   u   s   
zFileSystemStorage.deletec                 C   s
   | j | S r4   )rS   r<   r#   r#   r$   rW   y   rO   z FileSystemStorage._get_file_path)r   r    r!   r   rI   r'   rE   r=   rA   rB   r   rW   rP   r#   r#   rL   r$   r   d   s    r   zbce-python-sdkc                       s   e Zd Zdeddf fddZdedefddZded	eddfd
dZdeddfddZ	ddede
defddZdedefddZ  ZS )r   rG   r3   Nc                    sp   ddl m} ddlm} ddlm} t   |||j	 |j
	 |j|jd}||| _|j| _|j| _d S )Nr   )BceCredentials)BceClientConfiguration)	BosClient)credentialsr(   r-   )Zbaidubce.auth.bce_credentialsrb   Z!baidubce.bce_client_configurationrc   Z baidubce.services.bos.bos_clientrd   rH   rI   r)   Zget_secret_valuer*   r(   r-   _clientr+   _bucket_namer,   _key_prefix)r6   rG   rb   rc   rd   Zbos_cfgrL   r#   r$   rI      s   

zBOS.__init__r1   c                 C   s   |  |}| jj| j|dS N)r+   r1   )_get_full_keyrf   Zget_object_as_stringrg   r<   r#   r#   r$   r=      s   
zBOS.getr?   c                 C   s"   |  |}| jj| j||d d S )N)Zbucketr1   data)rj   rf   Zput_object_from_stringrg   r@   r#   r#   r$   rA      s   

zBOS.setc                 C   s    |  |}| jj| j|d d S ri   )rj   rf   Zdelete_objectrg   r<   r#   r#   r$   rB      s   
z
BOS.deleter0   r2   c                 C   s$   |  |}| jj| j||ddS )N)Zexpiration_in_secondsascii)rj   rf   Zgenerate_pre_signed_urlrg   decoder5   r#   r#   r$   r7      s   
zBOS.get_urlc                 C   s   | j r| j  d| S |S )N/)rh   r<   r#   r#   r$   rj      s   zBOS._get_full_keyr8   )r   r    r!   r   rI   r'   rE   r=   rA   rB   r/   r7   rj   rP   r#   r#   rL   r$   r   }   s    r   dicr3   c                C   sP   t t| }|jdkrt|S |jdkrt|S |jdkr"t|S t| d S )Nr   r&   r.   )r   r   Zvalidate_pythonr   r   r   r   r   )ro   rG   r#   r#   r$   r      s   


r   )$rC   osr   pathlibr   typingr   r   r   r   r   r	   Zpydanticr
   r   r   r   Ztyping_extensionsr   r   r   Z
utils.depsr   __all__r   r   r   r   r   ABCMetar   r   r   r   r'   r   r#   r#   r#   r$   <module>   s0    /