
    $g                        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 ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ dd	lmZm Z  dd
lmZmZ ddlmZ ddgZ	 	 	 	 	 	 ddededededeee ef                  dee          dee         dee         deee         ef         fdZ!	 	 	 	 	 ddededededeee ef                  dee          dee         deee         ef         fdZ"dedee         fdZ#dS )    )isawaitable)AnyAsyncIterableAsyncIteratorDictOptionalUnion   )GraphQLErrorlocated_error)collect_fields) assert_valid_execution_argumentsexecuteget_field_defExecutionContextExecutionResult)get_argument_values)DocumentNode)Pathinspect)GraphQLFieldResolverGraphQLSchema   )MapAsyncIterator	subscribecreate_source_event_streamNschemadocument
root_valuecontext_valuevariable_valuesoperation_namefield_resolversubscribe_field_resolverreturnc           	          K   t           ||           d{V }t          |t                    r|S dt          dt          f fd}	t	          ||	          S )ah  Create a GraphQL subscription.

    Implements the "Subscribe" algorithm described in the GraphQL spec.

    Returns a coroutine object which yields either an AsyncIterator (if successful) or
    an ExecutionResult (client error). The coroutine will raise an exception if a server
    error occurs.

    If the client-provided arguments to this function do not result in a compliant
    subscription, a GraphQL Response (ExecutionResult) with descriptive errors and no
    data will be returned.

    If the source stream could not be created due to faulty subscription resolver logic
    or underlying systems, the coroutine object will yield a single ExecutionResult
    containing ``errors`` and no ``data``.

    If the operation succeeded, the coroutine will yield an AsyncIterator, which yields
    a stream of ExecutionResults representing the response stream.
    Npayloadr%   c           	      d   K   t          |           }t          |          r| d{V n|S )a  Map source to response.

        For each payload yielded from a subscription, map it over the normal GraphQL
        :func:`~graphql.execute` function, with ``payload`` as the ``root_value``.
        This implements the "MapSourceToResponseEvent" algorithm described in the
        GraphQL specification. The :func:`~graphql.execute` function provides the
        "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
        "ExecuteQuery" algorithm, for which :func:`~graphql.execute` is also used.
        N)r   r   )r'   resultr    r   r#   r"   r   r!   s     [/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/graphql/execution/subscribe.pymap_source_to_responsez)subscribe.<locals>.map_source_to_responseF   sR       
 
  +622>V|||||||>    )r   
isinstancer   r   r   )
r   r   r   r    r!   r"   r#   r$   result_or_streamr+   s
   `` ````   r*   r   r      s      : 8         "O44  ?c ?o ? ? ? ? ? ? ? ? ? ? ?, ,.DEEEr,   c           	        K   t          | ||           t          j        | ||||||          }t          |t                    rt          d|          S 	 t          |           d{V }t          |t                    s t          dt          |           d          |S # t          $ r}	t          d|	g          cY d}	~	S d}	~	ww xY w)a,  Create source event stream

    Implements the "CreateSourceEventStream" algorithm described in the GraphQL
    specification, resolving the subscription source event stream.

    Returns a coroutine that yields an AsyncIterable.

    If the client-provided arguments to this function do not result in a compliant
    subscription, a GraphQL Response (ExecutionResult) with descriptive errors and no
    data will be returned.

    If the source stream could not be created due to faulty subscription resolver logic
    or underlying systems, the coroutine object will yield a single ExecutionResult
    containing ``errors`` and no ``data``.

    A source event stream represents a sequence of events, each of which triggers a
    GraphQL execution for that event.

    This may be useful when hosting the stateful subscription service in a different
    process or machine than the stateless GraphQL execution engine, or otherwise
    separating these two steps. For more on this, see the "Supporting Subscriptions
    at Scale" information in the GraphQL spec.
    )r$   N)dataerrorsz8Subscription field must return AsyncIterable. Received: .)r   r   buildr-   listr   execute_subscriptionr   	TypeErrorr   r   )
r   r   r   r    r!   r"   r$   contextevent_streamerrors
             r*   r   r   _   s$     D %VXGGG $!9  G '4   :D9999:1':::::::: ,66 	7%l337 7 7    : : :D%999999999:s   AB" "
C,C=CCr7   c                 $  K   | j         }|j        }|t          d| j                  t	          || j        | j        || j        j                  }t          t          |
                                                    \  }}t          |||d                   }|s&|d         j        j        }t          d| d|          t          d ||j                  }|                     ||||          }		 t!          ||d         | j                  }
|j        p| j        } || j        |	fi |
}|                     |          r| d {V }t+          |t,                    r||S # t,          $ r(}t/          |||                                          d }~ww xY w)Nz;Schema is not configured to execute subscription operation.r   zThe subscription field 'z' is not defined.)r   subscription_typer   	operationr   	fragmentsr!   selection_setnextiteritemsr   namevaluer   build_resolve_infor   r   r$   r   is_awaitabler-   	Exceptionr   as_list)r7   r   	root_typeroot_fieldsresponse_namefield_nodes	field_def
field_namepathinfoargs
resolve_fnr8   r9   s                 r*   r5   r5      s     ^F(II
 
 	

 !' K "&d;+<+<+>+>&?&?!@!@M;fiQ@@I 
 ^(.
DzDDDk
 
 	
 mY^44D%%iiNND
@ #9k!ng>UVV (LG,L
!z'"4dCCdCC-- 	.!-------LlI.. 	 @ @ @E;???@s   .A.E 
F'#F

F)NNNNNN)NNNNN)$r   r   typingr   r   r   r   r   r	   r9   r   r   execution.collect_fieldsr   execution.executer   r   r   r   r   execution.valuesr   languager   pyutilsr   typer   r   map_async_iteratorr   __all__strr   r   r5    r,   r*   <module>r]      s                        0 / / / / / / / 5 5 5 5 5 5              3 2 2 2 2 2 # # # # # # # # # # # # # # 6 6 6 6 6 6 6 6 0 0 0 0 0 04
5 04$(59?C?F ?F?F?F ?F 	?F
 d38n-?F SM?F 12?F '';<?F =)?:;?F ?F ?F ?FJ 04$(?CA: A:A:A: A: 	A:
 d38n-A: SMA: '';<A: =./A: A: A: A:H1@(8 1@]3=O 1@ 1@ 1@ 1@ 1@ 1@r,   