@@ -55,7 +55,7 @@ cdef class Packer(object):
5555 Convert unicode to bytes with this encoding. (default: 'utf-8')
5656 :param str unicode_errors:
5757 Error handler for encoding unicode. (default: 'strict')
58- :param bool precise_mode :
58+ :param bool strict_types :
5959 If set to true, types will be checked to be exact. Derived classes
6060 from serializeable types will not be serialized and will be
6161 treated as unsupported type and forwarded to default.
@@ -77,7 +77,7 @@ cdef class Packer(object):
7777 cdef object _berrors
7878 cdef char * encoding
7979 cdef char * unicode_errors
80- cdef bint precise_mode
80+ cdef bint strict_types
8181 cdef bool use_float
8282 cdef bint autoreset
8383
@@ -91,11 +91,11 @@ cdef class Packer(object):
9191
9292 def __init__ (self , default = None , encoding = ' utf-8' , unicode_errors = ' strict' ,
9393 use_single_float = False , bint autoreset = 1 , bint use_bin_type = 0 ,
94- bint precise_mode = 0 ):
94+ bint strict_types = 0 ):
9595 """
9696 """
9797 self .use_float = use_single_float
98- self .precise_mode = precise_mode
98+ self .strict_types = strict_types
9999 self .autoreset = autoreset
100100 self .pk.use_bin_type = use_bin_type
101101 if default is not None :
@@ -131,20 +131,20 @@ cdef class Packer(object):
131131 cdef dict d
132132 cdef size_t L
133133 cdef int default_used = 0
134- cdef bint precise = self .precise_mode
134+ cdef bint strict_types = self .strict_types
135135
136136 if nest_limit < 0 :
137137 raise PackValueError(" recursion limit exceeded." )
138138
139139 while True :
140140 if o is None :
141141 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 ):
143143 if o:
144144 ret = msgpack_pack_true(& self .pk)
145145 else :
146146 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):
148148 # PyInt_Check(long) is True for Python 3.
149149 # So we should test long before int.
150150 try :
@@ -161,25 +161,25 @@ cdef class Packer(object):
161161 continue
162162 else :
163163 raise
164- elif PyInt_CheckExact(o) if precise else PyInt_Check(o):
164+ elif PyInt_CheckExact(o) if strict_types else PyInt_Check(o):
165165 longval = o
166166 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):
168168 if self .use_float:
169169 fval = o
170170 ret = msgpack_pack_float(& self .pk, fval)
171171 else :
172172 dval = o
173173 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):
175175 L = len (o)
176176 if L > (2 ** 32 )- 1 :
177177 raise ValueError (" bytes is too large" )
178178 rawval = o
179179 ret = msgpack_pack_bin(& self .pk, L)
180180 if ret == 0 :
181181 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):
183183 if not self .encoding:
184184 raise TypeError (" Can't encode unicode string: no encoding is specified" )
185185 o = PyUnicode_AsEncodedString(o, self .encoding, self .unicode_errors)
@@ -202,7 +202,7 @@ cdef class Packer(object):
202202 if ret != 0 : break
203203 ret = self ._pack(v, nest_limit- 1 )
204204 if ret != 0 : break
205- elif not precise and PyDict_Check(o):
205+ elif not strict_types and PyDict_Check(o):
206206 L = len (o)
207207 if L > (2 ** 32 )- 1 :
208208 raise ValueError (" dict is too large" )
@@ -222,7 +222,7 @@ cdef class Packer(object):
222222 raise ValueError (" EXT data is too large" )
223223 ret = msgpack_pack_ext(& self .pk, longval, L)
224224 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)):
226226 L = len (o)
227227 if L > (2 ** 32 )- 1 :
228228 raise ValueError (" list is too large" )
0 commit comments