File tree Expand file tree Collapse file tree 2 files changed +5
-17
lines changed Expand file tree Collapse file tree 2 files changed +5
-17
lines changed Original file line number Diff line number Diff line change 2
2
from msgpack ._version import version
3
3
from msgpack .exceptions import *
4
4
5
+ from collections import namedtuple
5
6
6
- class ExtType (object ):
7
- __slots__ = ('code' , 'data' )
8
7
9
- def __init__ (self , code , data ):
8
+ class ExtType (namedtuple ('ExtType' , 'code data' )):
9
+ def __new__ (cls , code , data ):
10
10
if not isinstance (code , int ):
11
11
raise TypeError ("code must be int" )
12
12
if not isinstance (data , bytes ):
13
13
raise TypeError ("data must be bytes" )
14
14
if not 0 <= code <= 127 :
15
15
raise ValueError ("code must be 0~127" )
16
- self .code = code
17
- self .data = data
18
-
19
- def __eq__ (self , other ):
20
- if not isinstance (other , ExtType ):
21
- return NotImplemented
22
- return self .code == other .code and self .data == other .data
23
-
24
- def __hash__ (self ):
25
- return self .code ^ hash (self .data )
26
-
27
- def __repr__ (self ):
28
- return "msgpack.ExtType(%r, %r)" % (self .code , self .data )
16
+ return super (ExtType , cls ).__new__ (cls , code , data )
29
17
30
18
31
19
import os
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ cdef class Packer(object):
186
186
# This should be before Tuple because ExtType is namedtuple.
187
187
longval = o.code
188
188
rawval = o.data
189
- L = len (o[ 1 ] )
189
+ L = len (o.data )
190
190
ret = msgpack_pack_ext(& self .pk, longval, L)
191
191
ret = msgpack_pack_raw_body(& self .pk, rawval, L)
192
192
elif PyTuple_Check(o) or PyList_Check(o):
You can’t perform that action at this time.
0 commit comments