summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2015-11-10 03:30:11 +0900
committerINADA Naoki <songofacandy@gmail.com>2015-11-10 03:30:11 +0900
commitcbdf3c339a2c4c6b40a7e75dd96e457a024937f6 (patch)
tree4466c4a5960599770c94ee0130d3eff65c9a30cb
parente9a47cbd35ada9d29ebe1d7e8619103e0651d5b5 (diff)
downloadmsgpack-python-cbdf3c339a2c4c6b40a7e75dd96e457a024937f6.tar.gz
s/precise_mode/strict_types/
-rw-r--r--msgpack/_packer.pyx26
1 files changed, 13 insertions, 13 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index c015fcb..50d19ff 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -55,7 +55,7 @@ cdef class Packer(object):
Convert unicode to bytes with this encoding. (default: 'utf-8')
:param str unicode_errors:
Error handler for encoding unicode. (default: 'strict')
- :param bool precise_mode:
+ :param bool strict_types:
If set to true, types will be checked to be exact. Derived classes
from serializeable types will not be serialized and will be
treated as unsupported type and forwarded to default.
@@ -77,7 +77,7 @@ cdef class Packer(object):
cdef object _berrors
cdef char *encoding
cdef char *unicode_errors
- cdef bint precise_mode
+ cdef bint strict_types
cdef bool use_float
cdef bint autoreset
@@ -91,11 +91,11 @@ cdef class Packer(object):
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
use_single_float=False, bint autoreset=1, bint use_bin_type=0,
- bint precise_mode=0):
+ bint strict_types=0):
"""
"""
self.use_float = use_single_float
- self.precise_mode = precise_mode
+ self.strict_types = strict_types
self.autoreset = autoreset
self.pk.use_bin_type = use_bin_type
if default is not None:
@@ -131,7 +131,7 @@ cdef class Packer(object):
cdef dict d
cdef size_t L
cdef int default_used = 0
- cdef bint precise = self.precise_mode
+ cdef bint strict_types = self.strict_types
if nest_limit < 0:
raise PackValueError("recursion limit exceeded.")
@@ -139,12 +139,12 @@ cdef class Packer(object):
while True:
if o is None:
ret = msgpack_pack_nil(&self.pk)
- elif PyBool_Check(o) if precise else isinstance(o, bool):
+ elif PyBool_Check(o) if strict_types else isinstance(o, bool):
if o:
ret = msgpack_pack_true(&self.pk)
else:
ret = msgpack_pack_false(&self.pk)
- elif PyLong_CheckExact(o) if precise else PyLong_Check(o):
+ elif PyLong_CheckExact(o) if strict_types else PyLong_Check(o):
# PyInt_Check(long) is True for Python 3.
# So we should test long before int.
try:
@@ -161,17 +161,17 @@ cdef class Packer(object):
continue
else:
raise
- elif PyInt_CheckExact(o) if precise else PyInt_Check(o):
+ elif PyInt_CheckExact(o) if strict_types else PyInt_Check(o):
longval = o
ret = msgpack_pack_long(&self.pk, longval)
- elif PyFloat_CheckExact(o) if precise else PyFloat_Check(o):
+ elif PyFloat_CheckExact(o) if strict_types else PyFloat_Check(o):
if self.use_float:
fval = o
ret = msgpack_pack_float(&self.pk, fval)
else:
dval = o
ret = msgpack_pack_double(&self.pk, dval)
- elif PyBytes_CheckExact(o) if precise else PyBytes_Check(o):
+ elif PyBytes_CheckExact(o) if strict_types else PyBytes_Check(o):
L = len(o)
if L > (2**32)-1:
raise ValueError("bytes is too large")
@@ -179,7 +179,7 @@ cdef class Packer(object):
ret = msgpack_pack_bin(&self.pk, L)
if ret == 0:
ret = msgpack_pack_raw_body(&self.pk, rawval, L)
- elif PyUnicode_CheckExact(o) if precise else PyUnicode_Check(o):
+ elif PyUnicode_CheckExact(o) if strict_types else PyUnicode_Check(o):
if not self.encoding:
raise TypeError("Can't encode unicode string: no encoding is specified")
o = PyUnicode_AsEncodedString(o, self.encoding, self.unicode_errors)
@@ -202,7 +202,7 @@ cdef class Packer(object):
if ret != 0: break
ret = self._pack(v, nest_limit-1)
if ret != 0: break
- elif not precise and PyDict_Check(o):
+ elif not strict_types and PyDict_Check(o):
L = len(o)
if L > (2**32)-1:
raise ValueError("dict is too large")
@@ -222,7 +222,7 @@ cdef class Packer(object):
raise ValueError("EXT data is too large")
ret = msgpack_pack_ext(&self.pk, longval, L)
ret = msgpack_pack_raw_body(&self.pk, rawval, L)
- elif PyList_CheckExact(o) if precise else (PyTuple_Check(o) or PyList_Check(o)):
+ elif PyList_CheckExact(o) if strict_types else (PyTuple_Check(o) or PyList_Check(o)):
L = len(o)
if L > (2**32)-1:
raise ValueError("list is too large")