diff options
| author | 2011-09-26 17:34:53 +0200 | |
|---|---|---|
| committer | 2011-09-26 17:34:53 +0200 | |
| commit | da9f709fadbcb63bc8f6b2dd4d917d920af3fe42 (patch) | |
| tree | 33a75771ea3f447aac4a1a6d300f1a1055c83557 /cython/plist.pyx | |
| parent | b1ad30f5bf9c5067d1bdb5d7a5f9e62e9db5a137 (diff) | |
| download | libplist-da9f709fadbcb63bc8f6b2dd4d917d920af3fe42.tar.gz libplist-da9f709fadbcb63bc8f6b2dd4d917d920af3fe42.tar.bz2 | |
cython: use bint instead of bool, fix deprecated stuff
Diffstat (limited to 'cython/plist.pyx')
| -rw-r--r-- | cython/plist.pyx | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/cython/plist.pyx b/cython/plist.pyx index 5a305c4..4732d0f 100644 --- a/cython/plist.pyx +++ b/cython/plist.pyx | |||
| @@ -9,9 +9,8 @@ IF UNAME_MACHINE == 'x86_64': | |||
| 9 | ELSE: | 9 | ELSE: |
| 10 | ctypedef unsigned long long int uint64_t | 10 | ctypedef unsigned long long int uint64_t |
| 11 | 11 | ||
| 12 | cimport python_unicode | 12 | cimport cpython |
| 13 | cimport python_string | 13 | cimport libc.stdlib |
| 14 | cimport stdlib | ||
| 15 | 14 | ||
| 16 | cdef extern from *: | 15 | cdef extern from *: |
| 17 | ctypedef enum plist_type: | 16 | ctypedef enum plist_type: |
| @@ -105,10 +104,10 @@ cdef class Node: | |||
| 105 | plist_to_xml(self._c_node, &out, &length) | 104 | plist_to_xml(self._c_node, &out, &length) |
| 106 | 105 | ||
| 107 | try: | 106 | try: |
| 108 | return python_unicode.PyUnicode_DecodeUTF8(out, length, 'strict') | 107 | return cpython.PyUnicode_DecodeUTF8(out, length, 'strict') |
| 109 | finally: | 108 | finally: |
| 110 | if out != NULL: | 109 | if out != NULL: |
| 111 | stdlib.free(out) | 110 | libc.stdlib.free(out) |
| 112 | 111 | ||
| 113 | cpdef bytes to_bin(self): | 112 | cpdef bytes to_bin(self): |
| 114 | cdef: | 113 | cdef: |
| @@ -117,10 +116,10 @@ cdef class Node: | |||
| 117 | plist_to_bin(self._c_node, &out, &length) | 116 | plist_to_bin(self._c_node, &out, &length) |
| 118 | 117 | ||
| 119 | try: | 118 | try: |
| 120 | return python_string.PyString_FromStringAndSize(out, length) | 119 | return cpython.PyString_FromStringAndSize(out, length) |
| 121 | finally: | 120 | finally: |
| 122 | if out != NULL: | 121 | if out != NULL: |
| 123 | stdlib.free(out) | 122 | libc.stdlib.free(out) |
| 124 | 123 | ||
| 125 | property parent: | 124 | property parent: |
| 126 | def __get__(self): | 125 | def __get__(self): |
| @@ -147,7 +146,7 @@ cdef class Bool(Node): | |||
| 147 | return self.get_value() | 146 | return self.get_value() |
| 148 | 147 | ||
| 149 | def __richcmp__(self, other, op): | 148 | def __richcmp__(self, other, op): |
| 150 | cdef bool b = self.get_value() | 149 | cdef bint b = self.get_value() |
| 151 | if op == 0: | 150 | if op == 0: |
| 152 | return b < other | 151 | return b < other |
| 153 | if op == 1: | 152 | if op == 1: |
| @@ -168,7 +167,7 @@ cdef class Bool(Node): | |||
| 168 | cpdef set_value(self, object value): | 167 | cpdef set_value(self, object value): |
| 169 | plist_set_bool_val(self._c_node, bool(value)) | 168 | plist_set_bool_val(self._c_node, bool(value)) |
| 170 | 169 | ||
| 171 | cpdef bool get_value(self): | 170 | cpdef bint get_value(self): |
| 172 | cdef uint8_t value | 171 | cdef uint8_t value |
| 173 | plist_get_bool_val(self._c_node, &value) | 172 | plist_get_bool_val(self._c_node, &value) |
| 174 | return bool(value) | 173 | return bool(value) |
| @@ -271,7 +270,7 @@ cdef Real Real_factory(plist_t c_node, bint managed=True): | |||
| 271 | instance._c_node = c_node | 270 | instance._c_node = c_node |
| 272 | return instance | 271 | return instance |
| 273 | 272 | ||
| 274 | from python_version cimport PY_MAJOR_VERSION | 273 | from cpython cimport PY_MAJOR_VERSION |
| 275 | 274 | ||
| 276 | cdef class String(Node): | 275 | cdef class String(Node): |
| 277 | def __cinit__(self, object value=None, *args, **kwargs): | 276 | def __cinit__(self, object value=None, *args, **kwargs): |
| @@ -332,9 +331,9 @@ cdef class String(Node): | |||
| 332 | char* c_value = NULL | 331 | char* c_value = NULL |
| 333 | plist_get_string_val(self._c_node, &c_value) | 332 | plist_get_string_val(self._c_node, &c_value) |
| 334 | try: | 333 | try: |
| 335 | return python_unicode.PyUnicode_DecodeUTF8(c_value, stdlib.strlen(c_value), 'strict') | 334 | return cpython.PyUnicode_DecodeUTF8(c_value, libc.stdlib.strlen(c_value), 'strict') |
| 336 | finally: | 335 | finally: |
| 337 | stdlib.free(c_value) | 336 | libc.stdlib.free(c_value) |
| 338 | 337 | ||
| 339 | cdef String String_factory(plist_t c_node, bint managed=True): | 338 | cdef String String_factory(plist_t c_node, bint managed=True): |
| 340 | cdef String instance = String.__new__(String) | 339 | cdef String instance = String.__new__(String) |
| @@ -435,9 +434,9 @@ cdef class Data(Node): | |||
| 435 | plist_get_data_val(self._c_node, &val, &length) | 434 | plist_get_data_val(self._c_node, &val, &length) |
| 436 | 435 | ||
| 437 | try: | 436 | try: |
| 438 | return python_string.PyString_FromStringAndSize(val, length) | 437 | return cpython.PyString_FromStringAndSize(val, length) |
| 439 | finally: | 438 | finally: |
| 440 | stdlib.free(val) | 439 | libc.stdlib.free(val) |
| 441 | 440 | ||
| 442 | cpdef set_value(self, object value): | 441 | cpdef set_value(self, object value): |
| 443 | cdef: | 442 | cdef: |
| @@ -461,7 +460,7 @@ cdef plist_t create_dict_plist(object value=None): | |||
| 461 | c_node = NULL | 460 | c_node = NULL |
| 462 | return node | 461 | return node |
| 463 | 462 | ||
| 464 | cimport python_dict | 463 | cimport cpython |
| 465 | 464 | ||
| 466 | cdef class Dict(Node): | 465 | cdef class Dict(Node): |
| 467 | def __cinit__(self, object value=None, *args, **kwargs): | 466 | def __cinit__(self, object value=None, *args, **kwargs): |
| @@ -475,18 +474,18 @@ cdef class Dict(Node): | |||
| 475 | cdef char* key = NULL | 474 | cdef char* key = NULL |
| 476 | cdef plist_t subnode = NULL | 475 | cdef plist_t subnode = NULL |
| 477 | 476 | ||
| 478 | self._map = python_dict.PyDict_New() | 477 | self._map = cpython.PyDict_New() |
| 479 | 478 | ||
| 480 | plist_dict_new_iter(self._c_node, &it); | 479 | plist_dict_new_iter(self._c_node, &it); |
| 481 | plist_dict_next_item(self._c_node, it, &key, &subnode); | 480 | plist_dict_next_item(self._c_node, it, &key, &subnode); |
| 482 | 481 | ||
| 483 | while subnode is not NULL: | 482 | while subnode is not NULL: |
| 484 | python_dict.PyDict_SetItem(self._map, key, plist_t_to_node(subnode, False)) | 483 | cpython.PyDict_SetItem(self._map, key, plist_t_to_node(subnode, False)) |
| 485 | subnode = NULL | 484 | subnode = NULL |
| 486 | stdlib.free(key) | 485 | libc.stdlib.free(key) |
| 487 | key = NULL | 486 | key = NULL |
| 488 | plist_dict_next_item(self._c_node, it, &key, &subnode); | 487 | plist_dict_next_item(self._c_node, it, &key, &subnode); |
| 489 | stdlib.free(it) | 488 | libc.stdlib.free(it) |
| 490 | 489 | ||
| 491 | def __dealloc__(self): | 490 | def __dealloc__(self): |
| 492 | self._map = None | 491 | self._map = None |
| @@ -507,13 +506,13 @@ cdef class Dict(Node): | |||
| 507 | return d >= other | 506 | return d >= other |
| 508 | 507 | ||
| 509 | def __len__(self): | 508 | def __len__(self): |
| 510 | return python_dict.PyDict_Size(self._map) | 509 | return cpython.PyDict_Size(self._map) |
| 511 | 510 | ||
| 512 | def __repr__(self): | 511 | def __repr__(self): |
| 513 | return '<Dict: %s>' % self._map | 512 | return '<Dict: %s>' % self._map |
| 514 | 513 | ||
| 515 | cpdef dict get_value(self): | 514 | cpdef dict get_value(self): |
| 516 | cdef dict result = python_dict.PyDict_New() | 515 | cdef dict result = cpython.PyDict_New() |
| 517 | return dict([(key, value.get_value()) for key, value in self.items()]) | 516 | return dict([(key, value.get_value()) for key, value in self.items()]) |
| 518 | return result | 517 | return result |
| 519 | 518 | ||
| @@ -527,26 +526,26 @@ cdef class Dict(Node): | |||
| 527 | def __iter__(self): | 526 | def __iter__(self): |
| 528 | return self._map.__iter__() | 527 | return self._map.__iter__() |
| 529 | 528 | ||
| 530 | cpdef bool has_key(self, key): | 529 | cpdef bint has_key(self, key): |
| 531 | return self._map.has_key(key) | 530 | return self._map.has_key(key) |
| 532 | 531 | ||
| 533 | cpdef object get(self, key, default=None): | 532 | cpdef object get(self, key, default=None): |
| 534 | return self._map.get(key, default) | 533 | return self._map.get(key, default) |
| 535 | 534 | ||
| 536 | cpdef list keys(self): | 535 | cpdef list keys(self): |
| 537 | return python_dict.PyDict_Keys(self._map) | 536 | return cpython.PyDict_Keys(self._map) |
| 538 | 537 | ||
| 539 | cpdef object iterkeys(self): | 538 | cpdef object iterkeys(self): |
| 540 | return self._map.iterkeys() | 539 | return self._map.iterkeys() |
| 541 | 540 | ||
| 542 | cpdef list items(self): | 541 | cpdef list items(self): |
| 543 | return python_dict.PyDict_Items(self._map) | 542 | return cpython.PyDict_Items(self._map) |
| 544 | 543 | ||
| 545 | cpdef object iteritems(self): | 544 | cpdef object iteritems(self): |
| 546 | return self._map.iteritems() | 545 | return self._map.iteritems() |
| 547 | 546 | ||
| 548 | cpdef list values(self): | 547 | cpdef list values(self): |
| 549 | return python_dict.PyDict_Values(self._map) | 548 | return cpython.PyDict_Values(self._map) |
| 550 | return self._map.values() | 549 | return self._map.values() |
| 551 | 550 | ||
| 552 | cpdef object itervalues(self): | 551 | cpdef object itervalues(self): |
| @@ -566,7 +565,7 @@ cdef class Dict(Node): | |||
| 566 | self._map[key] = n | 565 | self._map[key] = n |
| 567 | 566 | ||
| 568 | def __delitem__(self, key): | 567 | def __delitem__(self, key): |
| 569 | python_dict.PyDict_DelItem(self._map, key) | 568 | cpython.PyDict_DelItem(self._map, key) |
| 570 | plist_dict_remove_item(self._c_node, key) | 569 | plist_dict_remove_item(self._c_node, key) |
| 571 | 570 | ||
| 572 | cdef Dict Dict_factory(plist_t c_node, bint managed=True): | 571 | cdef Dict Dict_factory(plist_t c_node, bint managed=True): |
