summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2015-11-10 03:33:50 +0900
committerINADA Naoki <songofacandy@gmail.com>2015-11-10 03:33:50 +0900
commit1032ef9bf2baef73b04f209181e42978ab4c71fe (patch)
treeb3a3157f5ea60c13983c830e9a21a2e528d5d8bd
parentcbdf3c339a2c4c6b40a7e75dd96e457a024937f6 (diff)
downloadmsgpack-python-1032ef9bf2baef73b04f209181e42978ab4c71fe.tar.gz
fallback unpacker: precise => strict
-rw-r--r--msgpack/fallback.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 0e37f74..cffecca 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -69,6 +69,13 @@ TYPE_EXT = 5
DEFAULT_RECURSE_LIMIT = 511
+def _check_type_strict(obj, t, type=type, tuple=tuple):
+ if type(t) is tuple:
+ return type(obj) in t
+ else:
+ return type(obj) is t
+
+
def unpack(stream, **kwargs):
"""
Unpack an object from `stream`.
@@ -601,7 +608,7 @@ 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.
@@ -618,9 +625,9 @@ class Packer(object):
It also enable str8 type for unicode.
"""
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
- precise_mode=False, use_single_float=False, autoreset=True,
+ strict_types=False, use_single_float=False, autoreset=True,
use_bin_type=False):
- self._precise_mode = precise_mode
+ self._strict_types = strict_types
self._use_float = use_single_float
self._autoreset = autoreset
self._use_bin_type = use_bin_type
@@ -632,17 +639,11 @@ class Packer(object):
raise TypeError("default must be callable")
self._default = default
- def _check_precise(obj, t, type=type, tuple=tuple):
- if type(t) is tuple:
- return type(obj) in t
- else:
- return type(obj) is t
-
def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT,
- check=isinstance, check_precise=_check_precise):
+ check=isinstance, check_type_strict=_check_type_strict):
default_used = False
- if self._precise_mode:
- check = check_precise
+ if self._strict_types:
+ check = check_type_strict
list_types = list
else:
list_types = (list, tuple)