frontmatter/__init__.py
def dump(post, fd, encoding='utf-8', handler=None, **kwargs):
    """
    Serialize :py:class:`post <frontmatter.Post>` to a string and write to a file-like object.
    Text will be encoded on the way out (utf-8 by default).

    ::

        >>> from io import BytesIO
        >>> f = BytesIO()
        >>> frontmatter.dump(post, f)
        >>> print(f.getvalue())
        ---
        excerpt: tl;dr
        layout: post
        title: Hello, world!
        ---
        Well, hello there, world.


    """
    content = dumps(post, handler, **kwargs)
    if hasattr(fd, 'write'):
        fd.write(content.encode(encoding))

    else:
        with codecs.open(fd, 'w', encoding) as f:
            f.write(content)
def dump(post, fd, encoding='utf-8', handler=None, **kwargs):
    """
    Serialize :py:class:`post <frontmatter.Post>` to a string and write to a file-like object.
    Text will be encoded on the way out (utf-8 by default).

    ::

        >>> from io import BytesIO
        >>> f = BytesIO()
        >>> frontmatter.dump(post, f)
        >>> print(f.getvalue())
        ---
        excerpt: tl;dr
        layout: post
        title: Hello, world!
        ---
        Well, hello there, world.


    """
    content = dumps(post, handler, **kwargs)
    if hasattr(fd, 'write'):
        fd.write(content.encode(encoding))

    else:
        with codecs.open(fd, 'w', encoding) as f:
            f.write(content)
Serialize :py:class:`post <frontmatter.Post>` to a string and write to a file-like object.
    Text will be encoded on the way out (utf-8 by default).

    ::

        >>> from io import BytesIO
        >>> f = BytesIO()
        >>> frontmatter.dump(post, f)
        >>> print(f.getvalue())
        ---
        excerpt: tl;dr
        layout: post
        title: Hello, world!
        ---
        Well, hello there, world.