docs: def save(matrix, version, out, kind=None, **kw):
      """\
      Serializes the matrix in any of the supported formats.
  
      :param matrix: The matrix to serialize.
      :param int version: The (Micro) QR code version
      :param out: A filename or a writable file-like object with a
              ``name`` attribute. If a stream like :py:class:`io.ByteIO` or
              :py:class:`io.StringIO` object without a ``name`` attribute is
              provided, use the `kind` parameter to specify the serialization
              format.
      :param kind: If the desired output format cannot be extracted from
              the filename, this parameter can be used to indicate the
              serialization format (i.e. "svg" to enforce SVG output)
      :param kw: Any of the supported keywords by the specific serialization
              method.
      """
      is_stream = False
      if kind is None:
          try:
              fname = out.name
              is_stream = True
          except AttributeError:
              fname = out
          ext = fname[fname.rfind('.') + 1:].lower()
      else:
          ext = kind.lower()
      if not is_stream and ext == 'svgz':
          f = gzip.open(out, 'wb', compresslevel=kw.pop('compresslevel', 9))
          try:
              _VALID_SERIALISERS['svg'](matrix, version, f, **kw)
          finally:
              f.close()
      else:
          if kw.pop('debug', False) and ext == 'svg':
              ext = 'svg_debug'
          try:
              _VALID_SERIALISERS[ext](matrix, version, out, **kw)
          except KeyError:
              raise ValueError('Unknown file extension ".{0}"'.format(ext))