class_docstr: Implements the ServerSentEvent Protocol:
  https://www.w3.org/TR/2009/WD-eventsource-20090421/
  
  Responses must not be compressed by middleware in order to work.
  implementation based on Starlette StreamingResponse
class_docstr_tok: ["Implements","the","ServerSentEvent","Protocol",":","https",":","\/\/www.w3.org\/TR\/2009\/WD-eventsource-20090421\/","Responses","must","not","be","compressed","by","middleware","in","order","to","work",".","implementation","based","on","Starlette","StreamingResponse"]
code: def __init__(
      self,
      content: Any,
      status_code: int = 200,
      headers: Optional[Dict] = None,
      media_type: str = "text/event-stream",
      background: Optional[BackgroundTask] = None,
      ping: Optional[int] = None,
      sep: Optional[str] = None,
      ping_message_factory: Optional[
          Callable[[], ServerSentEvent]
      ] = None,
      data_sender_callable: Optional[
          Callable[[], Coroutine[None, None, None]]
      ] = None,
  ) -> None:
      self.sep = sep
      self.ping_message_factory = ping_message_factory
      if isinstance(content, AsyncIterable):
          self.body_iterator = (
              content
          )  # type: AsyncIterable[Union[Any,dict,ServerSentEvent]]
      else:
          self.body_iterator = iterate_in_threadpool(content)  # type: ignore
      self.status_code = status_code
      self.media_type = (
          self.media_type if media_type is None else media_type
      )
      self.background = background  # type: ignore  # follows https://github.com/encode/starlette/blob/master/starlette/responses.py
      self.data_sender_callable = data_sender_callable
  
      _headers = {}
      if headers is not None:  # pragma: no cover
          _headers.update(headers)
  
      # mandatory for servers-sent events headers
      # allow cache control header to be set by user to support fan out proxies
      # https://www.fastly.com/blog/server-sent-events-fastly
      _headers.setdefault("Cache-Control", "no-cache")
      _headers["Connection"] = "keep-alive"
      _headers["X-Accel-Buffering"] = "no"
  
      self.init_headers(_headers)
  
      self.ping_interval = (
          self.DEFAULT_PING_INTERVAL if ping is None else ping
      )
      self.active = True
  
      self._ping_task = None
      self._send_lock = anyio.Lock()
  
imports: import enum
  import io
  import json
  import logging
  import re
  from datetime import datetime
  from functools import partial
  from typing import Any, AsyncIterable, Callable, Coroutine, Dict, Optional, Union
  import anyio
  from starlette.background import BackgroundTask
  from starlette.concurrency import iterate_in_threadpool
  from starlette.responses import Response
  from starlette.types import Receive, Scope, Send
label_desc: Use image node_id 1 to create a new EventSourceResponse object from inherited base classes: Response with example: obj = EventSourceResponse(content, status_code, headers, media_type, background, ping, sep, ping_message_factory, data_sender_callable)