summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cython/plist.pxd2
-rw-r--r--cython/plist.pyx35
2 files changed, 37 insertions, 0 deletions
diff --git a/cython/plist.pxd b/cython/plist.pxd
index 99dcca5..b11d80d 100644
--- a/cython/plist.pxd
+++ b/cython/plist.pxd
@@ -71,6 +71,8 @@ cpdef object from_bin(bytes bin)
71 71
72cpdef object load(fp, fmt=*, use_builtin_types=*, dict_type=*) 72cpdef object load(fp, fmt=*, use_builtin_types=*, dict_type=*)
73cpdef object loads(data, fmt=*, use_builtin_types=*, dict_type=*) 73cpdef object loads(data, fmt=*, use_builtin_types=*, dict_type=*)
74cpdef object dump(value, fp, fmt=*, sort_keys=*, skipkeys=*)
75cpdef object dumps(value, fmt=*, sort_keys=*, skipkeys=*)
74 76
75cdef object plist_t_to_node(plist_t c_plist, bint managed=*) 77cdef object plist_t_to_node(plist_t c_plist, bint managed=*)
76cdef plist_t native_to_plist_t(object native) 78cdef plist_t native_to_plist_t(object native)
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()