code: def ssl_options_to_context(
      ssl_options: Union[Dict[str, Any], ssl.SSLContext],
      server_side: Optional[bool] = None,
  ) -> ssl.SSLContext:
      """Try to convert an ``ssl_options`` dictionary to an
      `~ssl.SSLContext` object.
  
      The ``ssl_options`` dictionary contains keywords to be passed to
      ``ssl.SSLContext.wrap_socket``.  In Python 2.7.9+, `ssl.SSLContext` objects can
      be used instead.  This function converts the dict form to its
      `~ssl.SSLContext` equivalent, and may be used when a component which
      accepts both forms needs to upgrade to the `~ssl.SSLContext` version
      to use features like SNI or NPN.
  
      .. versionchanged:: 6.2
  
         Added server_side argument. Omitting this argument will
         result in a DeprecationWarning on Python 3.10.
  
      """
      if isinstance(ssl_options, ssl.SSLContext):
          return ssl_options
      assert isinstance(ssl_options, dict)
      assert all(
          k in _SSL_CONTEXT_KEYWORDS for k in ssl_options
      ), ssl_options
      # TODO: Now that we have the server_side argument, can we switch to
      # create_default_context or would that change behavior?
      default_version = ssl.PROTOCOL_TLS
      if server_side:
          default_version = ssl.PROTOCOL_TLS_SERVER
      elif server_side is not None:
          default_version = ssl.PROTOCOL_TLS_CLIENT
      context = ssl.SSLContext(
          ssl_options.get("ssl_version", default_version)
      )
      if "certfile" in ssl_options:
          context.load_cert_chain(
              ssl_options["certfile"], ssl_options.get("keyfile", None)
          )
      if "cert_reqs" in ssl_options:
          if ssl_options["cert_reqs"] == ssl.CERT_NONE:
              # This may have been set automatically by PROTOCOL_TLS_CLIENT but is
              # incompatible with CERT_NONE so we must manually clear it.
              context.check_hostname = False
          context.verify_mode = ssl_options["cert_reqs"]
      if "ca_certs" in ssl_options:
          context.load_verify_locations(ssl_options["ca_certs"])
      if "ciphers" in ssl_options:
          context.set_ciphers(ssl_options["ciphers"])
      if hasattr(ssl, "OP_NO_COMPRESSION"):
          # Disable TLS compression to avoid CRIME and related attacks.
          # This constant depends on openssl version 1.0.
          # TODO: Do we need to do this ourselves or can we trust
          # the defaults?
          context.options |= ssl.OP_NO_COMPRESSION
      return context
  
imports: import asyncio
  import concurrent.futures
  import errno
  import os
  import sys
  import socket
  import ssl
  import stat
  from tornado.concurrent import dummy_executor, run_on_executor
  from tornado.ioloop import IOLoop
  from tornado.util import Configurable, errno_from_exception
  from typing import List, Callable, Any, Type, Dict, Union, Tuple, Awaitable, Optional
label_desc: Use image node_id 5 for calling a global function with example usage: ssl_options_to_context(ssl_options, server_side) and returns: context, ssl_options