code: def _find_binary_writer(
      stream: t.IO[t.Any],
  ) -> t.Optional[t.BinaryIO]:
      # We need to figure out if the given stream is already binary.
      # This can happen because the official docs recommend detaching
      # the streams to get binary streams.  Some code might do this, so
      # we need to deal with this case explicitly.
      if _is_binary_writer(stream, False):
          return t.cast(t.BinaryIO, stream)
  
      buf = getattr(stream, "buffer", None)
  
      # Same situation here; this time we assume that the buffer is
      # actually binary in case it's closed.
      if buf is not None and _is_binary_writer(buf, True):
          return t.cast(t.BinaryIO, buf)
  
      return None
  
imports: import codecs
  import io
  import os
  import re
  import sys
  import typing
  from weakref import WeakKeyDictionary
label_desc: Use image node_id 7 for calling a global function with example usage: _find_binary_writer(stream) and returns: None, t, t