summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2013-10-21 01:12:57 +0900
committerINADA Naoki <inada-n@klab.com>2013-10-21 01:12:57 +0900
commitd84a403bc0bbbb36c4a5833e00269eef6c4a91ae (patch)
tree67e86c2d28bce248448c8bb92ba196c1381c5d12
parente3fee4db5fbf1ead4a98fff6c8843574480c3c2a (diff)
downloadmsgpack-python-d84a403bc0bbbb36c4a5833e00269eef6c4a91ae.tar.gz
fix bugs.
-rw-r--r--msgpack/__init__.py20
-rw-r--r--msgpack/_packer.pyx2
2 files changed, 5 insertions, 17 deletions
diff --git a/msgpack/__init__.py b/msgpack/__init__.py
index 56a0b36..a958025 100644
--- a/msgpack/__init__.py
+++ b/msgpack/__init__.py
@@ -2,30 +2,18 @@
from msgpack._version import version
from msgpack.exceptions import *
+from collections import namedtuple
-class ExtType(object):
- __slots__ = ('code', 'data')
- def __init__(self, code, data):
+class ExtType(namedtuple('ExtType', 'code data')):
+ def __new__(cls, code, data):
if not isinstance(code, int):
raise TypeError("code must be int")
if not isinstance(data, bytes):
raise TypeError("data must be bytes")
if not 0 <= code <= 127:
raise ValueError("code must be 0~127")
- self.code = code
- self.data = data
-
- def __eq__(self, other):
- if not isinstance(other, ExtType):
- return NotImplemented
- return self.code == other.code and self.data == other.data
-
- def __hash__(self):
- return self.code ^ hash(self.data)
-
- def __repr__(self):
- return "msgpack.ExtType(%r, %r)" % (self.code, self.data)
+ return super(ExtType, cls).__new__(cls, code, data)
import os
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index f2d058e..f261f08 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -186,7 +186,7 @@ cdef class Packer(object):
# This should be before Tuple because ExtType is namedtuple.
longval = o.code
rawval = o.data
- L = len(o[1])
+ L = len(o.data)
ret = msgpack_pack_ext(&self.pk, longval, L)
ret = msgpack_pack_raw_body(&self.pk, rawval, L)
elif PyTuple_Check(o) or PyList_Check(o):