docs: def _get_extension(file):
      """
      Gets the extension for the given file, which can be either a
      str or an ``open()``'ed file (which has a ``.name`` attribute).
      """
      if isinstance(file, str):
          return os.path.splitext(file)[-1]
      elif isinstance(file, bytes):
          kind = imghdr.what(io.BytesIO(file))
          return ('.' + kind) if kind else ''
      elif isinstance(file, io.IOBase) and file.seekable():
          kind = imghdr.what(file)
          return ('.' + kind) if kind is not None else ''
      elif getattr(file, 'name', None):
          # Note: ``file.name`` works for :tl:`InputFile` and some `IOBase`
          return _get_extension(file.name)
      else:
          return ''