summaryrefslogtreecommitdiffstats
path: root/cython/plist.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'cython/plist.pyx')
-rw-r--r--cython/plist.pyx35
1 files changed, 35 insertions, 0 deletions
diff --git a/cython/plist.pyx b/cython/plist.pyx
index 573f17f..3c6389c 100644
--- a/cython/plist.pyx
+++ b/cython/plist.pyx
@@ -907,3 +907,38 @@ cpdef object loads(data, fmt=None, use_builtin_types=True, dict_type=dict):
907 raise ValueError('Cannot parse XML property list as binary') 907 raise ValueError('Cannot parse XML property list as binary')
908 908
909 return cb(data) 909 return cb(data)
910
911cpdef object dump(value, fp, fmt=FMT_XML, sort_keys=True, skipkeys=False):
912 fp.write(dumps(value, fmt=fmt))
913
914cpdef object dumps(value, fmt=FMT_XML, sort_keys=True, skipkeys=False):
915 if fmt not in (FMT_XML, FMT_BINARY):
916 raise ValueError('Format must be constant FMT_XML or FMT_BINARY')
917
918 if check_datetime(value):
919 node = Date(value)
920 elif isinstance(value, unicode):
921 node = String(value)
922 elif PY_MAJOR_VERSION >= 3 and isinstance(value, bytes):
923 node = Data(value)
924 elif isinstance(value, str):
925 # See if this is binary
926 try:
927 node = String(value)
928 except ValueError:
929 node = Data(value)
930 elif isinstance(value, bool):
931 node = Bool(value)
932 elif isinstance(value, int):
933 node = Integer(value)
934 elif isinstance(value, float):
935 node = Real(value)
936 elif isinstance(value, dict):
937 node = Dict(value)
938 elif type(value) in (list, set, tuple):
939 node = Array(value)
940
941 if fmt == FMT_XML:
942 return node.to_xml()
943
944 return node.to_bin()