mirror of
				https://github.com/msgpack/msgpack-python.git
				synced 2025-10-31 01:20:53 +00:00 
			
		
		
		
	Fix minor bugs and tuning unpacking dict.
This commit is contained in:
		
							parent
							
								
									0536d1bd0c
								
							
						
					
					
						commit
						22920baae6
					
				
					 2 changed files with 17 additions and 10 deletions
				
			
		|  | @ -360,14 +360,17 @@ class Unpacker(object): | |||
|                     self._fb_unpack(EX_SKIP, write_bytes) | ||||
|                     self._fb_unpack(EX_SKIP, write_bytes) | ||||
|                 return | ||||
|             ret = [] | ||||
|             for i in xrange(n): | ||||
|                 ret.append((self._fb_unpack(EX_CONSTRUCT, write_bytes), | ||||
|                             self._fb_unpack(EX_CONSTRUCT, write_bytes))) | ||||
|             if self.object_pairs_hook is not None: | ||||
|                 ret = self.object_pairs_hook(ret) | ||||
|                 ret = self.object_pairs_hook( | ||||
|                         (self._fb_unpack(EX_CONSTRUCT, write_bytes), | ||||
|                          self._fb_unpack(EX_CONSTRUCT, write_bytes)) | ||||
|                             for _ in xrange(n) | ||||
|                         ) | ||||
|             else: | ||||
|                 ret = dict(ret) | ||||
|                 ret = {} | ||||
|                 for _ in xrange(n): | ||||
|                     key = self._fb_unpack(EX_CONSTRUCT, write_bytes) | ||||
|                     ret[key] = self._fb_unpack(EX_CONSTRUCT, write_bytes) | ||||
|                 if self.object_hook is not None: | ||||
|                     ret = self.object_hook(ret) | ||||
|             return ret | ||||
|  | @ -421,7 +424,7 @@ class Packer(object): | |||
|                 raise TypeError("default must be callable") | ||||
|         self._default = default | ||||
| 
 | ||||
|     def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT): | ||||
|     def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT, isinstance=isinstance): | ||||
|         if nest_limit < 0: | ||||
|             raise PackValueError("recursion limit exceeded") | ||||
|         if obj is None: | ||||
|  | @ -454,6 +457,10 @@ class Packer(object): | |||
|             raise PackValueError("Integer value out of range") | ||||
|         if isinstance(obj, (Unicode, bytes)): | ||||
|             if isinstance(obj, Unicode): | ||||
|                 if self.encoding is None: | ||||
|                     raise TypeError( | ||||
|                             "Can't encode unicode string: " | ||||
|                             "no encoding is specified") | ||||
|                 obj = obj.encode(self.encoding, self.unicode_errors) | ||||
|             n = len(obj) | ||||
|             if n <= 0x1f: | ||||
|  |  | |||
|  | @ -151,7 +151,7 @@ def test_odict(): | |||
|     od = odict(seq) | ||||
|     assert unpackb(packb(od), use_list=1) == dict(seq) | ||||
|     def pair_hook(seq): | ||||
|         return seq | ||||
|         return list(seq) | ||||
|     assert unpackb(packb(od), object_pairs_hook=pair_hook, use_list=1) == seq | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 INADA Naoki
						INADA Naoki