def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    elif (fmt == FMT_XML):
        writer = plistlib.PlistWriter(fp)

        def writeDict(d):
            if d:
                writer.beginElement('dict')
                items = (sorted(d.items()) if sort_keys else d.items())
                for (key, value) in items:
                    if (not isinstance(key, (str, unicode))):
                        if skipkeys:
                            continue
                        raise TypeError('keys must be strings')
                    writer.simpleElement('key', key)
                    writer.writeValue(value)
                writer.endElement('dict')
            else:
                writer.simpleElement('dict')
        writer.writeDict = writeDict
        writer.writeln('<plist version="1.0">')
        writer.writeValue(value)
        writer.writeln('</plist>')
    elif (fmt == FMT_BINARY):
        writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
        writer.write(value)
    else:
        raise ValueError('Unsupported format: {}'.format(fmt))
def dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
    if _check_py3():
        plistlib.dump(value, fp, fmt=fmt, sort_keys=sort_keys, skipkeys=skipkeys)
    elif (fmt == FMT_XML):
        writer = plistlib.PlistWriter(fp)

        def writeDict(d):
            if d:
                writer.beginElement('dict')
                items = (sorted(d.items()) if sort_keys else d.items())
                for (key, value) in items:
                    if (not isinstance(key, (str, unicode))):
                        if skipkeys:
                            continue
                        raise TypeError('keys must be strings')
                    writer.simpleElement('key', key)
                    writer.writeValue(value)
                writer.endElement('dict')
            else:
                writer.simpleElement('dict')
        writer.writeDict = writeDict
        writer.writeln('<plist version="1.0">')
        writer.writeValue(value)
        writer.writeln('</plist>')
    elif (fmt == FMT_BINARY):
        writer = _BinaryPlistWriter(fp, sort_keys=sort_keys, skipkeys=skipkeys)
        writer.write(value)
    else:
        raise ValueError('Unsupported format: {}'.format(fmt))