@@ -55,7 +55,7 @@ cdef class Packer(object):
55
55
Convert unicode to bytes with this encoding. (default: 'utf-8')
56
56
:param str unicode_errors:
57
57
Error handler for encoding unicode. (default: 'strict')
58
- :param bool precise_mode :
58
+ :param bool strict_types :
59
59
If set to true, types will be checked to be exact. Derived classes
60
60
from serializeable types will not be serialized and will be
61
61
treated as unsupported type and forwarded to default.
@@ -77,7 +77,7 @@ cdef class Packer(object):
77
77
cdef object _berrors
78
78
cdef char * encoding
79
79
cdef char * unicode_errors
80
- cdef bint precise_mode
80
+ cdef bint strict_types
81
81
cdef bool use_float
82
82
cdef bint autoreset
83
83
@@ -91,11 +91,11 @@ cdef class Packer(object):
91
91
92
92
def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' ,
93
93
use_single_float = False , bint autoreset = 1 , bint use_bin_type = 0 ,
94
- bint precise_mode = 0 ):
94
+ bint strict_types = 0 ):
95
95
"""
96
96
"""
97
97
self .use_float = use_single_float
98
- self .precise_mode = precise_mode
98
+ self .strict_types = strict_types
99
99
self .autoreset = autoreset
100
100
self .pk.use_bin_type = use_bin_type
101
101
if default is not None :
@@ -131,20 +131,20 @@ cdef class Packer(object):
131
131
cdef dict d
132
132
cdef size_t L
133
133
cdef int default_used = 0
134
- cdef bint precise = self .precise_mode
134
+ cdef bint strict_types = self .strict_types
135
135
136
136
if nest_limit < 0 :
137
137
raise PackValueError(" recursion limit exceeded." )
138
138
139
139
while True :
140
140
if o is None :
141
141
ret = msgpack_pack_nil(& self .pk)
142
- elif PyBool_Check(o) if precise else isinstance (o, bool ):
142
+ elif PyBool_Check(o) if strict_types else isinstance (o, bool ):
143
143
if o:
144
144
ret = msgpack_pack_true(& self .pk)
145
145
else :
146
146
ret = msgpack_pack_false(& self .pk)
147
- elif PyLong_CheckExact(o) if precise else PyLong_Check(o):
147
+ elif PyLong_CheckExact(o) if strict_types else PyLong_Check(o):
148
148
# PyInt_Check(long) is True for Python 3.
149
149
# So we should test long before int.
150
150
try :
@@ -161,25 +161,25 @@ cdef class Packer(object):
161
161
continue
162
162
else :
163
163
raise
164
- elif PyInt_CheckExact(o) if precise else PyInt_Check(o):
164
+ elif PyInt_CheckExact(o) if strict_types else PyInt_Check(o):
165
165
longval = o
166
166
ret = msgpack_pack_long(& self .pk, longval)
167
- elif PyFloat_CheckExact(o) if precise else PyFloat_Check(o):
167
+ elif PyFloat_CheckExact(o) if strict_types else PyFloat_Check(o):
168
168
if self .use_float:
169
169
fval = o
170
170
ret = msgpack_pack_float(& self .pk, fval)
171
171
else :
172
172
dval = o
173
173
ret = msgpack_pack_double(& self .pk, dval)
174
- elif PyBytes_CheckExact(o) if precise else PyBytes_Check(o):
174
+ elif PyBytes_CheckExact(o) if strict_types else PyBytes_Check(o):
175
175
L = len (o)
176
176
if L > (2 ** 32 )- 1 :
177
177
raise ValueError (" bytes is too large" )
178
178
rawval = o
179
179
ret = msgpack_pack_bin(& self .pk, L)
180
180
if ret == 0 :
181
181
ret = msgpack_pack_raw_body(& self .pk, rawval, L)
182
- elif PyUnicode_CheckExact(o) if precise else PyUnicode_Check(o):
182
+ elif PyUnicode_CheckExact(o) if strict_types else PyUnicode_Check(o):
183
183
if not self .encoding:
184
184
raise TypeError (" Can't encode unicode string: no encoding is specified" )
185
185
o = PyUnicode_AsEncodedString(o, self .encoding, self .unicode_errors)
@@ -202,7 +202,7 @@ cdef class Packer(object):
202
202
if ret != 0 : break
203
203
ret = self ._pack(v, nest_limit- 1 )
204
204
if ret != 0 : break
205
- elif not precise and PyDict_Check(o):
205
+ elif not strict_types and PyDict_Check(o):
206
206
L = len (o)
207
207
if L > (2 ** 32 )- 1 :
208
208
raise ValueError (" dict is too large" )
@@ -222,7 +222,7 @@ cdef class Packer(object):
222
222
raise ValueError (" EXT data is too large" )
223
223
ret = msgpack_pack_ext(& self .pk, longval, L)
224
224
ret = msgpack_pack_raw_body(& self .pk, rawval, L)
225
- elif PyList_CheckExact(o) if precise else (PyTuple_Check(o) or PyList_Check(o)):
225
+ elif PyList_CheckExact(o) if strict_types else (PyTuple_Check(o) or PyList_Check(o)):
226
226
L = len (o)
227
227
if L > (2 ** 32 )- 1 :
228
228
raise ValueError (" list is too large" )
0 commit comments