o
    xi                     @   sf   d dl Z d dlmZmZmZmZ d dlmZ ddlm	Z	 e 
eZG dd deZG dd	 d	eZdS )
    N)parseintrospection_querybuild_ast_schemabuild_client_schema)validate   )LocalSchemaTransportc                       s    e Zd ZdZ fddZ  ZS )
RetryErrorz.Custom exception thrown when retry logic failsc                    s&   d||f }t t| | || _d S )NzFailed %s retries: %s)superr	   __init__last_exception)selfretries_countr   message	__class__ [/home/ubuntu/.local/lib/python3.10/site-packages/wandb/vendor/gql-0.2.0/wandb_gql/client.pyr      s   
zRetryError.__init__)__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r	      s    r	   c                   @   s2   e Zd Z		dddZdd Zdd	 Zd
d ZdS )ClientNFr   c                 C   s   |r|rJ d|r|r|rJ d| ttj}|r'|r"J dt|}n|r8|r/J dt|}t|}n|r@|s@t|}|| _|| _|| _	|| _
d S )Nz;Cant provide introspection type definition at the same timez;Cant fetch the schema from transport if is already providedz6Cant provide introspection and schema at the same timez8Cant provide Type definition and schema at the same time)executer   r   datar   r   r   schemaintrospection	transportretries)r   r   r   type_defr   fetch_schema_from_transportr   type_def_astr   r   r   r      s"   


zClient.__init__c                 C   s*   | j stdt| j |}|r|d d S )Nz@Cannot validate locally the document, you need to pass a schema.r   )r   	Exceptionr   )r   documentvalidation_errorsr   r   r   r   )   s   zClient.validatec                 O   sF   | j r| | | j|g|R i |}|jr tt|jd |jS )Nr   )r   r   _get_resulterrorsr#   strr   )r   r$   argskwargsresultr   r   r   r   0   s   
zClient.executec              
   O   s   | j s| jj|g|R i |S d }d}|| j k r_z;z| jj|g|R i |}|W W |d7 }S  tyN } z|}tjd||d dd W Y d }~nd }~ww W |d7 }n|d7 }w || j k st||)Nr   r   z=Request failed with exception %s. Retrying for the %s time...T)exc_info)r   r   r   r#   logwarningr	   )r   r$   r)   r*   r   r   r+   er   r   r   r&   :   s(   




zClient._get_result)NNNNFr   )r   r   r   r   r   r   r&   r   r   r   r   r      s    

r   )loggingwandb_graphqlr   r   r   r   wandb_graphql.validationr   transport.local_schemar   	getLoggerr   r-   r#   r	   objectr   r   r   r   r   <module>   s    
