a
    $ñ»jÅ%  ã                   @  s  d dl mZ d dlZd dlZd dlmZ ddlmZ ddlm	Z	 G dd„ de
ƒZG d	d
„ d
ejƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZeG dd„ dƒƒZdddœdd„Zddddœdd„Zd+dddddœdd „Zddd!d"d#œd$d%„Zd,dd&d&dd'd(œd)d*„ZdS )-é    )ÚannotationsN)Ú	dataclassé   )ÚT_JSON_DICT)Ústoragec                      sB   e Zd ZdZddœdd„Zedd dœdd„ƒZ‡ fd	d
„Z‡  ZS )ÚCacheIdz&Unique identifier of the Cache object.Ústr©Úreturnc                 C  s   | S ©N© ©Úselfr   r   ú9E:\soccer\ml_env\Lib\site-packages\mycdp/cache_storage.pyÚto_json   s    zCacheId.to_json©Újsonr
   c                 C  s   | |ƒS r   r   ©Úclsr   r   r   r   Ú	from_json   s    zCacheId.from_jsonc                   s   d  tƒ  ¡ ¡S )NzCacheId({}))ÚformatÚsuperÚ__repr__r   ©Ú	__class__r   r   r      s    zCacheId.__repr__)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr   r   Ú__classcell__r   r   r   r   r      s
   r   c                   @  sJ   e Zd ZdZdZdZdZdZdZdZ	dd	œd
d„Z
edd dœdd„ƒZdS )ÚCachedResponseTypezType of HTTP response cached.ÚbasicZcorsÚdefaultÚerrorZopaqueResponseZopaqueRedirectr   r	   c                 C  s   | j S r   )Úvaluer   r   r   r   r   '   s    zCachedResponseType.to_jsonr   c                 C  s   | |ƒS r   r   r   r   r   r   r   *   s    zCachedResponseType.from_jsonN)r   r   r   r   ZBASICZCORSÚDEFAULTÚERRORZOPAQUE_RESPONSEZOPAQUE_REDIRECTr   r   r   r   r   r   r   r!      s   r!   c                   @  st   e Zd ZU dZded< ded< ded< ded< d	ed
< ded< ded< ded< ddœdd„Zedd dœdd„ƒZdS )Ú	DataEntryzData entry.r   Úrequest_urlÚrequest_methodútyping.List[Header]Úrequest_headersÚfloatÚresponse_timeÚintÚresponse_statusÚresponse_status_textr!   Úresponse_typeÚresponse_headersr   r	   c                 C  sr   t ƒ }| j|d< | j|d< dd„ | jD ƒ|d< | j|d< | j|d< | j|d< | j ¡ |d	< d
d„ | j	D ƒ|d< |S )NÚ
requestURLÚrequestMethodc                 S  s   g | ]}|  ¡ ‘qS r   ©r   ©Ú.0Úir   r   r   Ú
<listcomp>G   ó    z%DataEntry.to_json.<locals>.<listcomp>ÚrequestHeadersÚresponseTimeÚresponseStatusÚresponseStatusTextÚresponseTypec                 S  s   g | ]}|  ¡ ‘qS r   r6   r7   r   r   r   r:   L   r;   ÚresponseHeaders)
Údictr)   r*   r,   r.   r0   r1   r2   r   r3   ©r   r   r   r   r   r   C   s    




zDataEntry.to_jsonr   c                 C  sr   | t | d¡ƒt | d¡ƒdd„ |d D ƒt| d¡ƒt| d¡ƒt | d¡ƒt | d	¡¡d
d„ |d D ƒd�S )Nr4   r5   c                 S  s   g | ]}t  |¡‘qS r   ©ÚHeaderr   r7   r   r   r   r:   T   s   z'DataEntry.from_json.<locals>.<listcomp>r<   r=   r>   r?   r@   c                 S  s   g | ]}t  |¡‘qS r   rD   r7   r   r   r   r:   ]   s   rA   )r)   r*   r,   r.   r0   r1   r2   r3   )r   Úgetr-   r/   r!   r   r   r   r   r   r   O   s     ÿÿÿôzDataEntry.from_jsonN©r   r   r   r   Ú__annotations__r   r   r   r   r   r   r   r(   /   s   
r(   c                   @  s`   e Zd ZU dZded< ded< ded< ded< dZd	ed
< ddœdd„Zedd dœdd„ƒZdS )ÚCachezCache identifier.r   Úcache_idr   Úsecurity_originÚstorage_keyÚ
cache_nameNú&typing.Optional[storage.StorageBucket]Ústorage_bucketr   r	   c                 C  sN   t ƒ }| j ¡ |d< | j|d< | j|d< | j|d< | jd urJ| j ¡ |d< |S )NÚcacheIdÚsecurityOriginÚ
storageKeyÚ	cacheNameÚstorageBucket)rB   rJ   r   rK   rL   rM   rO   rC   r   r   r   r   q   s    



zCache.to_jsonr   c              
   C  s^   | t  | d¡¡t| d¡ƒt| d¡ƒt| d¡ƒ| dd ¡d urVtj | d¡¡nd d�S )NrP   rQ   rR   rS   rT   )rJ   rK   rL   rM   rO   )r   r   rF   r   r   ZStorageBucketr   r   r   r   r   {   s    ÿøzCache.from_json)	r   r   r   r   rH   rO   r   r   r   r   r   r   r   rI   c   s   

rI   c                   @  s@   e Zd ZU ded< ded< ddœdd„Zedd dœd	d
„ƒZdS )rE   r   Únamer%   r   r	   c                 C  s   t ƒ }| j|d< | j|d< |S )NrU   r%   )rB   rU   r%   rC   r   r   r   r   �   s    

zHeader.to_jsonr   c                 C  s    | t | d¡ƒt | d¡ƒd�S )NrU   r%   )rU   r%   ©r   rF   r   r   r   r   r   •   s    þzHeader.from_jsonN)r   r   r   rH   r   r   r   r   r   r   r   rE   Š   s
   
rE   c                   @  s<   e Zd ZU dZded< ddœdd„Zedd dœd	d
„ƒZdS )ÚCachedResponsezCached response.r   Úbodyr   r	   c                 C  s   t ƒ }| j|d< |S )NrX   )rB   rX   rC   r   r   r   r   ¤   s    
zCachedResponse.to_jsonr   c                 C  s   | t | d¡ƒd�S )NrX   )rX   rV   r   r   r   r   r   ©   s    ÿzCachedResponse.from_jsonNrG   r   r   r   r   rW   �   s
   
rW   z0typing.Generator[T_JSON_DICT, T_JSON_DICT, None])rJ   r
   c                 c  s&   t ƒ }|  ¡ |d< d|dœ}|V }dS )zI
    Deletes a cache.
    :param cache_id: Id of cache for deletion.
    rP   zCacheStorage.deleteCache©ÚmethodÚparamsN©rB   r   )rJ   r[   Úcmd_dictr   r   r   r   Údelete_cache°   s    þr^   r   )rJ   Úrequestr
   c                 c  s.   t ƒ }|  ¡ |d< ||d< d|dœ}|V }dS )z�
    Deletes a cache entry.
    :param cache_id: Id of cache where the entry will be deleted.
    :param request: URL spec of the request.
    rP   r_   zCacheStorage.deleteEntryrY   Nr\   )rJ   r_   r[   r]   r   r   r   r   Údelete_entryÀ   s    þr`   ztyping.Optional[str]rN   z>typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[Cache]])rK   rL   rO   r
   c                 c  s\   t ƒ }| dur| |d< |dur&||d< |dur:| ¡ |d< d|dœ}|V }dd„ |d	 D ƒS )
a‡  
    Requests cache names.
    :param security_origin: *(Optional)*
     At least and at most one of securityOrigin, storageKey,
     storageBucket must be specified. Security origin.
    :param storage_key: *(Optional)* Storage key.
    :param storage_bucket: *(Optional)* Storage bucket.
     If not specified, it uses the default bucket.
    :returns: Caches for the security origin.
    NrQ   rR   rT   zCacheStorage.requestCacheNamesrY   c                 S  s   g | ]}t  |¡‘qS r   )rI   r   r7   r   r   r   r:   í   r;   z'request_cache_names.<locals>.<listcomp>Úcachesr\   )rK   rL   rO   r[   r]   r   r   r   r   Úrequest_cache_namesÒ   s    þrb   r+   z:typing.Generator[T_JSON_DICT, T_JSON_DICT, CachedResponse])rJ   r)   r,   r
   c                 c  sL   t ƒ }|  ¡ |d< ||d< dd„ |D ƒ|d< d|dœ}|V }t | d¡¡S )	zé
    Fetches cache entry.
    :param cache_id: Id of cache that contains the entry.
    :param request_url: URL spec of the request.
    :param request_headers: headers of the request.
    :returns: Response read from the cache.
    rP   r4   c                 S  s   g | ]}|  ¡ ‘qS r   r6   r7   r   r   r   r:   ý   r;   z+request_cached_response.<locals>.<listcomp>r<   z"CacheStorage.requestCachedResponserY   Úresponse)rB   r   rW   r   rF   )rJ   r)   r,   r[   r]   r   r   r   r   Úrequest_cached_responseð   s    
þrd   ztyping.Optional[int]zWtyping.Generator[T_JSON_DICT, T_JSON_DICT, typing.Tuple[typing.List[DataEntry], float]])rJ   Ú
skip_countÚ	page_sizeÚpath_filterr
   c                 c  sr   t ƒ }|  ¡ |d< |dur"||d< |dur2||d< |durB||d< d|dœ}|V }dd	„ |d
 D ƒt| d¡ƒfS )a]  
    Requests data from cache.
    :param cache_id: ID of cache to get entries from.
    :param skip_count: *(Optional)* Number of records to skip.
    :param page_size: *(Optional)* Number of records to fetch.
    :param path_filter: *(Optional)* If present,
     only return the entries containing this substring in the path
    :returns: A tuple with the following items:
        0. **cacheDataEntries** - Array of object store data entries.
        1. **returnCount** - Count of returned entries from this storage. If
        pathFilter is empty, it is the count of all entries from this storage.
    rP   NZ	skipCountZpageSizeZ
pathFilterzCacheStorage.requestEntriesrY   c                 S  s   g | ]}t  |¡‘qS r   )r(   r   r7   r   r   r   r:   (  r;   z#request_entries.<locals>.<listcomp>ZcacheDataEntriesZreturnCount)rB   r   r-   rF   )rJ   re   rf   rg   r[   r]   r   r   r   r   Úrequest_entries  s    þþrh   )NNN)NNN)Ú
__future__r   ÚenumÚtypingÚdataclassesr   Úutilr   Ú r   r   r   ÚEnumr!   r(   rI   rE   rW   r^   r`   rb   rd   rh   r   r   r   r   Ú<module>   s4   3&   ý   ü