summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Bryan Forbes2011-09-26 17:18:01 +0200
committerGravatar Nikias Bassen2011-09-26 17:18:01 +0200
commitb1ad30f5bf9c5067d1bdb5d7a5f9e62e9db5a137 (patch)
treeae9bd48056a07dfe9c0477e324c322bc94a30519
parentbf1dcaecc3e7c4a123059ff5347bc5180835dbad (diff)
downloadlibplist-b1ad30f5bf9c5067d1bdb5d7a5f9e62e9db5a137.tar.gz
libplist-b1ad30f5bf9c5067d1bdb5d7a5f9e62e9db5a137.tar.bz2
More qualifiers.
-rw-r--r--cython/plist.pxd8
-rw-r--r--cython/plist.pyx34
2 files changed, 23 insertions, 19 deletions
diff --git a/cython/plist.pxd b/cython/plist.pxd
index 7cff51c..81a272e 100644
--- a/cython/plist.pxd
+++ b/cython/plist.pxd
@@ -24,15 +24,15 @@ cdef class Real(Node):
24 cpdef float get_value(self) 24 cpdef float get_value(self)
25 25
26cdef class String(Node): 26cdef class String(Node):
27 cpdef set_value(self, unicode value) 27 cpdef set_value(self, object value)
28 cpdef unicode get_value(self) 28 cpdef unicode get_value(self)
29 29
30cdef class Date(Node): 30cdef class Date(Node):
31 cpdef set_value(self, value) 31 cpdef set_value(self, object value)
32 cpdef object get_value(self) 32 cpdef object get_value(self)
33 33
34cdef class Data(Node): 34cdef class Data(Node):
35 cpdef set_value(self, bytes value) 35 cpdef set_value(self, object value)
36 cpdef bytes get_value(self) 36 cpdef bytes get_value(self)
37 37
38cdef class Dict(Node): 38cdef class Dict(Node):
@@ -54,7 +54,7 @@ cdef class Array(Node):
54 cdef void _init(self) 54 cdef void _init(self)
55 cpdef set_value(self, value) 55 cpdef set_value(self, value)
56 cpdef list get_value(self) 56 cpdef list get_value(self)
57 cpdef append(self, item) 57 cpdef append(self, object item)
58 58
59cpdef object from_xml(xml) 59cpdef object from_xml(xml)
60cpdef object from_bin(bytes bin) 60cpdef object from_bin(bytes bin)
diff --git a/cython/plist.pyx b/cython/plist.pyx
index aa4f0d8..5a305c4 100644
--- a/cython/plist.pyx
+++ b/cython/plist.pyx
@@ -107,7 +107,8 @@ cdef class Node:
107 try: 107 try:
108 return python_unicode.PyUnicode_DecodeUTF8(out, length, 'strict') 108 return python_unicode.PyUnicode_DecodeUTF8(out, length, 'strict')
109 finally: 109 finally:
110 stdlib.free(out) 110 if out != NULL:
111 stdlib.free(out)
111 112
112 cpdef bytes to_bin(self): 113 cpdef bytes to_bin(self):
113 cdef: 114 cdef:
@@ -118,7 +119,8 @@ cdef class Node:
118 try: 119 try:
119 return python_string.PyString_FromStringAndSize(out, length) 120 return python_string.PyString_FromStringAndSize(out, length)
120 finally: 121 finally:
121 stdlib.free(out) 122 if out != NULL:
123 stdlib.free(out)
122 124
123 property parent: 125 property parent:
124 def __get__(self): 126 def __get__(self):
@@ -135,7 +137,7 @@ cdef class Node:
135 return str(self.get_value()) 137 return str(self.get_value())
136 138
137cdef class Bool(Node): 139cdef class Bool(Node):
138 def __cinit__(self, value=None, *args, **kwargs): 140 def __cinit__(self, object value=None, *args, **kwargs):
139 if value is None: 141 if value is None:
140 self._c_node = plist_new_bool(0) 142 self._c_node = plist_new_bool(0)
141 else: 143 else:
@@ -178,7 +180,7 @@ cdef Bool Bool_factory(plist_t c_node, bint managed=True):
178 return instance 180 return instance
179 181
180cdef class Integer(Node): 182cdef class Integer(Node):
181 def __cinit__(self, value=None, *args, **kwargs): 183 def __cinit__(self, object value=None, *args, **kwargs):
182 if value is None: 184 if value is None:
183 self._c_node = plist_new_uint(0) 185 self._c_node = plist_new_uint(0)
184 else: 186 else:
@@ -224,7 +226,7 @@ cdef Integer Integer_factory(plist_t c_node, bint managed=True):
224 return instance 226 return instance
225 227
226cdef class Real(Node): 228cdef class Real(Node):
227 def __cinit__(self, value=None, *args, **kwargs): 229 def __cinit__(self, object value=None, *args, **kwargs):
228 if value is None: 230 if value is None:
229 self._c_node = plist_new_real(0.0) 231 self._c_node = plist_new_real(0.0)
230 else: 232 else:
@@ -272,7 +274,7 @@ cdef Real Real_factory(plist_t c_node, bint managed=True):
272from python_version cimport PY_MAJOR_VERSION 274from python_version cimport PY_MAJOR_VERSION
273 275
274cdef class String(Node): 276cdef class String(Node):
275 def __cinit__(self, value=None, *args, **kwargs): 277 def __cinit__(self, object value=None, *args, **kwargs):
276 cdef: 278 cdef:
277 char* c_utf8_data = NULL 279 char* c_utf8_data = NULL
278 bytes utf8_data 280 bytes utf8_data
@@ -308,7 +310,7 @@ cdef class String(Node):
308 if op == 5: 310 if op == 5:
309 return s >= other 311 return s >= other
310 312
311 cpdef set_value(self, unicode value): 313 cpdef set_value(self, object value):
312 cdef: 314 cdef:
313 char* c_utf8_data = NULL 315 char* c_utf8_data = NULL
314 bytes utf8_data 316 bytes utf8_data
@@ -357,7 +359,7 @@ cdef plist_t create_date_plist(value=None):
357 return node 359 return node
358 360
359cdef class Date(Node): 361cdef class Date(Node):
360 def __cinit__(self, value=None, *args, **kwargs): 362 def __cinit__(self, object value=None, *args, **kwargs):
361 self._c_node = create_date_plist(value) 363 self._c_node = create_date_plist(value)
362 364
363 def __repr__(self): 365 def __repr__(self):
@@ -401,7 +403,7 @@ cdef Date Date_factory(plist_t c_node, bint managed=True):
401 return instance 403 return instance
402 404
403cdef class Data(Node): 405cdef class Data(Node):
404 def __cinit__(self, value=None, *args, **kwargs): 406 def __cinit__(self, object value=None, *args, **kwargs):
405 if value is None: 407 if value is None:
406 self._c_node = plist_new_data(NULL, 0) 408 self._c_node = plist_new_data(NULL, 0)
407 else: 409 else:
@@ -437,8 +439,10 @@ cdef class Data(Node):
437 finally: 439 finally:
438 stdlib.free(val) 440 stdlib.free(val)
439 441
440 cpdef set_value(self, bytes value): 442 cpdef set_value(self, object value):
441 plist_set_data_val(self._c_node, value, len(value)) 443 cdef:
444 bytes py_val = value
445 plist_set_data_val(self._c_node, py_val, len(value))
442 446
443cdef Data Data_factory(plist_t c_node, bint managed=True): 447cdef Data Data_factory(plist_t c_node, bint managed=True):
444 cdef Data instance = Data.__new__(Data) 448 cdef Data instance = Data.__new__(Data)
@@ -460,7 +464,7 @@ cdef plist_t create_dict_plist(object value=None):
460cimport python_dict 464cimport python_dict
461 465
462cdef class Dict(Node): 466cdef class Dict(Node):
463 def __cinit__(self, value=None, *args, **kwargs): 467 def __cinit__(self, object value=None, *args, **kwargs):
464 self._c_node = create_dict_plist(value) 468 self._c_node = create_dict_plist(value)
465 469
466 def __init__(self, value=None, *args, **kwargs): 470 def __init__(self, value=None, *args, **kwargs):
@@ -584,7 +588,7 @@ cdef plist_t create_array_plist(object value=None):
584 return node 588 return node
585 589
586cdef class Array(Node): 590cdef class Array(Node):
587 def __cinit__(self, value=None, *args, **kwargs): 591 def __cinit__(self, object value=None, *args, **kwargs):
588 self._c_node = create_array_plist(value) 592 self._c_node = create_array_plist(value)
589 593
590 def __init__(self, value=None, *args, **kwargs): 594 def __init__(self, value=None, *args, **kwargs):
@@ -623,7 +627,7 @@ cdef class Array(Node):
623 cpdef list get_value(self): 627 cpdef list get_value(self):
624 return [i.get_value() for i in self] 628 return [i.get_value() for i in self]
625 629
626 cpdef set_value(self, value): 630 cpdef set_value(self, object value):
627 self._array = [] 631 self._array = []
628 plist_free(self._c_node) 632 plist_free(self._c_node)
629 self._c_node = NULL 633 self._c_node = NULL
@@ -655,7 +659,7 @@ cdef class Array(Node):
655 del self._array[index] 659 del self._array[index]
656 plist_array_remove_item(self._c_node, index) 660 plist_array_remove_item(self._c_node, index)
657 661
658 cpdef append(self, item): 662 cpdef append(self, object item):
659 cdef Node n 663 cdef Node n
660 664
661 if isinstance(item, Node): 665 if isinstance(item, Node):