python: Add test for python3 and fix found problems.

This commit is contained in:
INADA Naoki
2010-09-02 02:16:28 +09:00
parent 2146f5f623
commit 8d0d2bd3fc
6 changed files with 266 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ cdef extern from "Python.h":
cdef unsigned long long PyLong_AsUnsignedLongLong(object o)
cdef bint PyBool_Check(object o)
cdef bint PyMapping_Check(object o)
cdef bint PyDict_Check(object o)
cdef bint PySequence_Check(object o)
cdef bint PyLong_Check(object o)
cdef bint PyInt_Check(object o)
@@ -69,13 +69,14 @@ cdef class Packer(object):
def __dealloc__(self):
free(self.pk.buf);
cdef int __pack(self, object o) except -1:
cdef int _pack(self, object o) except -1:
cdef long long llval
cdef unsigned long long ullval
cdef long longval
cdef double fval
cdef char* rawval
cdef int ret
cdef dict d
if o is None:
ret = msgpack_pack_nil(&self.pk)
@@ -109,19 +110,20 @@ cdef class Packer(object):
ret = msgpack_pack_raw(&self.pk, len(o))
if ret == 0:
ret = msgpack_pack_raw_body(&self.pk, rawval, len(o))
elif PyMapping_Check(o):
ret = msgpack_pack_map(&self.pk, len(o))
elif PyDict_Check(o):
d = o
ret = msgpack_pack_map(&self.pk, len(d))
if ret == 0:
for k,v in o.iteritems():
ret = self.__pack(k)
for k,v in d.items():
ret = self._pack(k)
if ret != 0: break
ret = self.__pack(v)
ret = self._pack(v)
if ret != 0: break
elif PySequence_Check(o):
ret = msgpack_pack_array(&self.pk, len(o))
if ret == 0:
for v in o:
ret = self.__pack(v)
ret = self._pack(v)
if ret != 0: break
else:
# TODO: Serialize with defalt() like simplejson.
@@ -130,7 +132,7 @@ cdef class Packer(object):
def pack(self, object obj):
cdef int ret
ret = self.__pack(obj)
ret = self._pack(obj)
if ret:
raise TypeError
buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length)