diff options
| author | 2013-03-19 17:24:25 +0100 | |
|---|---|---|
| committer | 2013-03-19 17:24:25 +0100 | |
| commit | 1b12d348f7efd0a5a1ead163a68111b1def98e8d (patch) | |
| tree | 6ad7ad4f5e20e79d72568d1bd1fc3db0c79c67a4 | |
| parent | ef7347435a77a97444e61a52ce9305c3924d2df6 (diff) | |
| download | libplist-1b12d348f7efd0a5a1ead163a68111b1def98e8d.tar.gz libplist-1b12d348f7efd0a5a1ead163a68111b1def98e8d.tar.bz2 | |
cython: added PLIST_UID support
| -rw-r--r-- | cython/plist.pxd | 4 | ||||
| -rw-r--r-- | cython/plist.pyx | 51 |
2 files changed, 55 insertions, 0 deletions
diff --git a/cython/plist.pxd b/cython/plist.pxd index c504599..ee8a65e 100644 --- a/cython/plist.pxd +++ b/cython/plist.pxd | |||
| @@ -21,6 +21,10 @@ cdef class Integer(Node): | |||
| 21 | cpdef set_value(self, object value) | 21 | cpdef set_value(self, object value) |
| 22 | cpdef uint64_t get_value(self) | 22 | cpdef uint64_t get_value(self) |
| 23 | 23 | ||
| 24 | cdef class Uid(Node): | ||
| 25 | cpdef set_value(self, object value) | ||
| 26 | cpdef uint64_t get_value(self) | ||
| 27 | |||
| 24 | cdef class Key(Node): | 28 | cdef class Key(Node): |
| 25 | cpdef set_value(self, object value) | 29 | cpdef set_value(self, object value) |
| 26 | cpdef unicode get_value(self) | 30 | cpdef unicode get_value(self) |
diff --git a/cython/plist.pyx b/cython/plist.pyx index 09c0bbc..4eccdb1 100644 --- a/cython/plist.pyx +++ b/cython/plist.pyx | |||
| @@ -13,6 +13,7 @@ cdef extern from *: | |||
| 13 | PLIST_DATE, | 13 | PLIST_DATE, |
| 14 | PLIST_DATA, | 14 | PLIST_DATA, |
| 15 | PLIST_KEY, | 15 | PLIST_KEY, |
| 16 | PLIST_UID, | ||
| 16 | PLIST_NONE | 17 | PLIST_NONE |
| 17 | 18 | ||
| 18 | plist_t plist_new_bool(uint8_t val) | 19 | plist_t plist_new_bool(uint8_t val) |
| @@ -35,6 +36,10 @@ cdef extern from *: | |||
| 35 | void plist_get_key_val(plist_t node, char **val) | 36 | void plist_get_key_val(plist_t node, char **val) |
| 36 | void plist_set_key_val(plist_t node, char *val) | 37 | void plist_set_key_val(plist_t node, char *val) |
| 37 | 38 | ||
| 39 | plist_t plist_new_uid(uint64_t val) | ||
| 40 | void plist_get_uid_val(plist_t node, uint64_t *val) | ||
| 41 | void plist_set_uid_val(plist_t node, uint64_t val) | ||
| 42 | |||
| 38 | plist_t plist_new_string(char *val) | 43 | plist_t plist_new_string(char *val) |
| 39 | void plist_get_string_val(plist_t node, char **val) | 44 | void plist_get_string_val(plist_t node, char **val) |
| 40 | void plist_set_string_val(plist_t node, char *val) | 45 | void plist_set_string_val(plist_t node, char *val) |
| @@ -264,6 +269,52 @@ cdef Real Real_factory(plist_t c_node, bint managed=True): | |||
| 264 | instance._c_node = c_node | 269 | instance._c_node = c_node |
| 265 | return instance | 270 | return instance |
| 266 | 271 | ||
| 272 | cdef class Uid(Node): | ||
| 273 | def __cinit__(self, object value=None, *args, **kwargs): | ||
| 274 | if value is None: | ||
| 275 | self._c_node = plist_new_uid(0) | ||
| 276 | else: | ||
| 277 | self._c_node = plist_new_uid(int(value)) | ||
| 278 | |||
| 279 | def __repr__(self): | ||
| 280 | cdef uint64_t i = self.get_value() | ||
| 281 | return '<Uid: %s>' % i | ||
| 282 | |||
| 283 | def __int__(self): | ||
| 284 | return self.get_value() | ||
| 285 | |||
| 286 | def __float__(self): | ||
| 287 | return float(self.get_value()) | ||
| 288 | |||
| 289 | def __richcmp__(self, other, op): | ||
| 290 | cdef int i = self.get_value() | ||
| 291 | if op == 0: | ||
| 292 | return i < other | ||
| 293 | if op == 1: | ||
| 294 | return i <= other | ||
| 295 | if op == 2: | ||
| 296 | return i == other | ||
| 297 | if op == 3: | ||
| 298 | return i != other | ||
| 299 | if op == 4: | ||
| 300 | return i > other | ||
| 301 | if op == 5: | ||
| 302 | return i >= other | ||
| 303 | |||
| 304 | cpdef set_value(self, object value): | ||
| 305 | plist_set_uid_val(self._c_node, int(value)) | ||
| 306 | |||
| 307 | cpdef uint64_t get_value(self): | ||
| 308 | cdef uint64_t value | ||
| 309 | plist_get_uid_val(self._c_node, &value) | ||
| 310 | return value | ||
| 311 | |||
| 312 | cdef Uid Uid_factory(plist_t c_node, bint managed=True): | ||
| 313 | cdef Uid instance = Uid.__new__(Uid) | ||
| 314 | instance._c_managed = managed | ||
| 315 | instance._c_node = c_node | ||
| 316 | return instance | ||
| 317 | |||
| 267 | from cpython cimport PY_MAJOR_VERSION | 318 | from cpython cimport PY_MAJOR_VERSION |
| 268 | 319 | ||
| 269 | cdef class Key(Node): | 320 | cdef class Key(Node): |
