@@ -69,6 +69,13 @@ def getvalue(self):
69
69
DEFAULT_RECURSE_LIMIT = 511
70
70
71
71
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
+
72
79
def unpack (stream , ** kwargs ):
73
80
"""
74
81
Unpack an object from `stream`.
@@ -601,7 +608,7 @@ class Packer(object):
601
608
Convert unicode to bytes with this encoding. (default: 'utf-8')
602
609
:param str unicode_errors:
603
610
Error handler for encoding unicode. (default: 'strict')
604
- :param bool precise_mode :
611
+ :param bool strict_types :
605
612
If set to true, types will be checked to be exact. Derived classes
606
613
from serializeable types will not be serialized and will be
607
614
treated as unsupported type and forwarded to default.
@@ -618,9 +625,9 @@ class Packer(object):
618
625
It also enable str8 type for unicode.
619
626
"""
620
627
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 ,
622
629
use_bin_type = False ):
623
- self ._precise_mode = precise_mode
630
+ self ._strict_types = strict_types
624
631
self ._use_float = use_single_float
625
632
self ._autoreset = autoreset
626
633
self ._use_bin_type = use_bin_type
@@ -632,17 +639,11 @@ def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
632
639
raise TypeError ("default must be callable" )
633
640
self ._default = default
634
641
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
-
641
642
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 ):
643
644
default_used = False
644
- if self ._precise_mode :
645
- check = check_precise
645
+ if self ._strict_types :
646
+ check = check_type_strict
646
647
list_types = list
647
648
else :
648
649
list_types = (list , tuple )
0 commit comments