8000 fallback unpacker: precise => strict · palaviv/msgpack-python@1032ef9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1032ef9

Browse files
committed
fallback unpacker: precise => strict
1 parent cbdf3c3 commit 1032ef9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

msgpack/fallback.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def getvalue(self):
6969
DEFAULT_RECURSE_LIMIT = 511
7070

7171

72+
def _check_type_strict(obj, t, type=type, tuple=tuple):
73+
if type(t) is tuple:
74+
return type(obj) in t
75+
else:
76+
return type(obj) is t
77+
78+
7279
def unpack(stream, **kwargs):
7380
"""
7481
Unpack an object from `stream`.
@@ -601,7 +608,7 @@ class Packer(object):
601608
Convert unicode to bytes with this encoding. (default: 'utf-8')
602609
:param str unicode_errors:
603610
Error handler for encoding unicode. (default: 'strict')
604-
:param bool precise_mode:
611+
:param bool strict_types:
605612
If set to true, types will be checked to be exact. Derived classes
606613
from serializeable types will not be serialized and will be
607614
treated as unsupported type and forwarded to default.
@@ -618,9 +625,9 @@ class Packer(object):
618625
It also enable str8 type for unicode.
619626
"""
620627
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
621-
precise_mode=False, use_single_float=False, autoreset=True,
628+
strict_types=False, use_single_float=False, autoreset=True,
622629
use_bin_type=False):
623-
self._precise_mode = precise_mode
630+
self._strict_types = strict_types
624631
self._use_float = use_single_float
625632
self._autoreset = autoreset
626633
self._use_bin_type = use_bin_type
@@ -632,17 +639,11 @@ def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
632639
raise TypeError("default must be callable")
633640
self._default = default
634641

635-
def _check_precise(obj, t, type=type, tuple=tuple):
636-
if type(t) is tuple:
637-
return type(obj) in t
638-
else:
639-
return type(obj) is t
640-
641642
def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT,
642-
check=isinstance, check_precise=_check_precise):
643+
check=isinstance, check_type_strict=_check_type_strict):
643644
default_used = False
644-
if self._precise_mode:
645-
check = check_precise
645+
if self._strict_types:
646+
check = check_type_strict
646647
list_types = list
647648
else:
648649
list_types = (list, tuple)

0 commit comments

Comments
 (0)
0