o
    ûT·j«  ã                   @   s”  U d dl mZmZ d dlmZ d dlmZmZmZm	Z	 d dl
mZ dddiddiddidd d	œd
œdœZeeef ed< G dd„ deƒZdedB dededB fdd„ZdedB dedB fdd„ZdedB dedB fdd„ZG dd„ deƒZdedee fdd„ZddddddœdeedB ed ƒf d!eedB ed"ƒf d#eedB ed$ƒf d%eedB ed&ƒf d'eedB ed(ƒf defd)d*„Zd+Zd,Zeed-< dS ).é    )Ú	AnnotatedÚAny)ÚDoc)ÚAfterValidatorÚ	BaseModelÚFieldÚmodel_validator)ÚStreamingResponseÚobjectÚtypeÚstringÚinteger)r   Úminimum)ÚdataÚeventÚidÚretry)r   Ú
propertiesÚ_SSE_EVENT_SCHEMAc                   @   s   e Zd ZdZdZdS )ÚEventSourceResponseaæ  Streaming response with `text/event-stream` media type.

    Use as `response_class=EventSourceResponse` on a *path operation* that uses `yield`
    to enable Server Sent Events (SSE) responses.

    Works with **any HTTP method** (`GET`, `POST`, etc.), which makes it compatible
    with protocols like MCP that stream SSE over `POST`.

    The actual encoding logic lives in the FastAPI routing layer. This class
    serves mainly as a marker and sets the correct `Content-Type`.
    ztext/event-streamN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
media_type© r   r   úN/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/fastapi/sse.pyr      s    r   ÚvNÚ
field_nameÚreturnc                 C   s,   | d urd| v sd| v rt d|› d�ƒ‚| S )NúÚ
zSSE 'z' must be a single line)Ú
ValueError)r   r   r   r   r   Ú_check_single_line$   s   r#   c                 C   s
   t | dƒS )Nr   )r#   ©r   r   r   r   Ú_check_event_single_line*   s   
r%   c                 C   s"   | d urd| v rt dƒ‚t| dƒS )Nú z)SSE 'id' must not contain null charactersr   )r"   r#   r$   r   r   r   Ú_check_id_valid.   s   
r'   c                   @   sÞ   e Zd ZU dZdZeeedƒf ed< dZ	ee
dB edƒf ed< dZee
dB eeƒedƒf ed< dZee
dB eeƒed	ƒf ed
< dZeedB edd�edƒf ed< dZee
dB edƒf ed< edd�ddd„ƒZdS )ÚServerSentEventat  Represents a single Server-Sent Event.

    When `yield`ed from a *path operation function* that uses
    `response_class=EventSourceResponse`, each `ServerSentEvent` is encoded
    into the [SSE wire format](https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream)
    (`text/event-stream`).

    If you yield a plain object (dict, Pydantic model, etc.) instead, it is
    automatically JSON-encoded and sent as the `data:` field.

    All `data` values **including plain strings** are JSON-serialized.

    For example, `data="hello"` produces `data: "hello"` on the wire (with
    quotes).
    NaB  
            The event payload.

            Can be any JSON-serializable value: a Pydantic model, dict, list,
            string, number, etc. It is **always** serialized to JSON: strings
            are quoted (`"hello"` becomes `data: "hello"` on the wire).

            Mutually exclusive with `raw_data`.
            r   aQ  
            Raw string to send as the `data:` field **without** JSON encoding.

            Use this when you need to send pre-formatted text, HTML fragments,
            CSV lines, or any non-JSON payload. The string is placed directly
            into the `data:` field as-is.

            Mutually exclusive with `data`.
            Úraw_datazë
            Optional event type name.

            Maps to `addEventListener(event, ...)` on the browser. When omitted,
            the browser dispatches on the generic `message` event. Must be a
            single line.
            r   zó
            Optional event ID.

            The browser sends this value back as the `Last-Event-ID` header on
            automatic reconnection. **Must be a single line** and must not contain
            null (`\0`) characters.
            r   r   )Úgez×
            Optional reconnection time in **milliseconds**.

            Tells the browser how long to wait before reconnecting after the
            connection is lost. Must be a non-negative integer.
            r   zû
            Optional comment line(s).

            Comment lines start with `:` in the SSE wire format and are ignored by
            `EventSource` clients. Useful for keep-alive pings to prevent
            proxy/load-balancer timeouts.
            ÚcommentÚafter)Úmoder   c                 C   s    | j d ur| jd urtdƒ‚| S )Nz“Cannot set both 'data' and 'raw_data' on the same ServerSentEvent. Use 'data' for JSON-serialized payloads or 'raw_data' for pre-formatted strings.)r   r)   r"   )Úselfr   r   r   Ú_check_data_exclusive”   s
   ÿz%ServerSentEvent._check_data_exclusive)r   r(   )r   r   r   r   r   r   r   r   Ú__annotations__r)   Ústrr   r   r%   r   r'   r   Úintr   r+   r   r/   r   r   r   r   r(   4   sn   
 óÿÿÿóÿÿÿôÿþÿôÿþÿõÿþÿõÿÿÿr(   Úvaluec                 C   s   |   dd¡  dd¡ d¡S )Nz
r!   r    )ÚreplaceÚsplit)r3   r   r   r   Ú_split_sse_linesŸ   s   r6   )Údata_strr   r   r   r+   r7   zQ
            Pre-serialized data string to use as the `data:` field.
            r   zD
            Optional event type name (`event:` field).
            r   z:
            Optional event ID (`id:` field).
            r   zV
            Optional reconnection time in milliseconds (`retry:` field).
            r+   z@
            Optional comment line(s) (`:` prefix).
            c                 C   s¼   g }|durt |ƒD ]
}| d|› �¡ q
|dur!| d|› �¡ | dur4t | ƒD ]
}| d|› �¡ q)|dur@| d|› �¡ |durL| d|› �¡ | d¡ | d¡ d |¡ d	¡S )
z~Build SSE wire-format bytes from **pre-serialized** data.

    The result always ends with `\n\n` (the event terminator).
    Nz: zevent: zdata: zid: zretry: Ú r!   zutf-8)r6   ÚappendÚjoinÚencode)r7   r   r   r   r+   ÚlinesÚliner   r   r   Úformat_sse_event¥   s    /

r>   s   : ping

g      .@Ú_PING_INTERVAL)Útypingr   r   Úannotated_docr   Úpydanticr   r   r   r   Ústarlette.responsesr	   r   Údictr1   r0   r   r#   r%   r'   r(   Úlistr6   r2   Úbytesr>   ÚKEEPALIVE_COMMENTr?   Úfloatr   r   r   r   Ú<module>   s†    üþk×ÿÿÿþ
ÿÿÿöÿÿÿîÿÿÿæ"ÿÿÿÞ*
ÖH