mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
fix bugs.
This commit is contained in:
parent
e3fee4db5f
commit
d84a403bc0
2 changed files with 5 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue