def dump(obj, fp, **kw):
    r"""Dump python object to file.

    >>> import lazyxml
    >>> data = {'demo': {'foo': 1, 'bar': 2}}
    >>> lazyxml.dump(data, 'dump.xml')
    >>> with open('dump-fp.xml', 'w') as fp:
    >>>     lazyxml.dump(data, fp)

    >>> from cStringIO import StringIO
    >>> data = {'demo': {'foo': 1, 'bar': 2}}
    >>> buffer = StringIO()
    >>> lazyxml.dump(data, buffer)
    >>> buffer.getvalue()
    <?xml version="1.0" encoding="utf-8"?><demo><foo><![CDATA[1]]></foo><bar><![CDATA[2]]></bar></demo>
    >>> buffer.close()

    .. note::
        ``kw`` argument have the same meaning as in :func:`dumps`

    :param obj: data for dump to xml.
    :param fp: a filename or a file or file-like object that support ``.write()`` to write the xml content

    .. versionchanged:: 1.2
        The `fp` is a filename of string before this. It can now be a file or file-like object that support ``.write()`` to write the xml content.
    """
    xml = dumps(obj, **kw)
    if isinstance(fp, basestring):
        with open(fp, 'w') as fobj:
            fobj.write(xml)
    else:
        fp.write(xml)
def dump ( obj , fp , ** kw ) : xml = dumps ( obj , ** kw ) if isinstance ( fp , basestring ) : with open ( fp , 'w' ) as fobj : fobj . write ( xml ) else : fp . write ( xml )
r"""Dump python object to file.

    >>> import lazyxml
    >>> data = {'demo': {'foo': 1, 'bar': 2}}
    >>> lazyxml.dump(data, 'dump.xml')
    >>> with open('dump-fp.xml', 'w') as fp:
    >>>     lazyxml.dump(data, fp)

    >>> from cStringIO import StringIO
    >>> data = {'demo': {'foo': 1, 'bar': 2}}
    >>> buffer = StringIO()
    >>> lazyxml.dump(data, buffer)
    >>> buffer.getvalue()
    <?xml version="1.0" encoding="utf-8"?><demo><foo><![CDATA[1]]></foo><bar><![CDATA[2]]></bar></demo>
    >>> buffer.close()

    .. note::
        ``kw`` argument have the same meaning as in :func:`dumps`

    :param obj: data for dump to xml.
    :param fp: a filename or a file or file-like object that support ``.write()`` to write the xml content

    .. versionchanged:: 1.2
        The `fp` is a filename of string before this. It can now be a file or file-like object that support ``.write()`` to write the xml content.