mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	 f416981691
			
		
	
	
		f416981691
		
	
	
	
	
		
			
			for bytes. This is the default protocol. It intentionally cannot be unpickled by Python 2.x. - When a pickle written by Python 2.x contains an (8-bit) str instance, this is now decoded to a (Unicode) str instance. The encoding used to do this defaults to ASCII, but can be overridden via two new keyword arguments to the Unpickler class. Previously this would create bytes instances, which is usually wrong: str instances are often used to pickle attribute names etc., and text is more common than binary data anyway.
		
			
				
	
	
		
			24 lines
		
	
	
	
		
			606 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			606 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| import pickle
 | |
| import pickletools
 | |
| from test import test_support
 | |
| from test.pickletester import AbstractPickleTests
 | |
| from test.pickletester import AbstractPickleModuleTests
 | |
| 
 | |
| class OptimizedPickleTests(AbstractPickleTests, AbstractPickleModuleTests):
 | |
| 
 | |
|     def dumps(self, arg, proto=None):
 | |
|         return pickletools.optimize(pickle.dumps(arg, proto))
 | |
| 
 | |
|     def loads(self, buf):
 | |
|         return pickle.loads(buf)
 | |
| 
 | |
|     module = pickle
 | |
|     error = KeyError
 | |
| 
 | |
| def test_main():
 | |
|     test_support.run_unittest(OptimizedPickleTests)
 | |
|     test_support.run_doctest(pickletools)
 | |
| 
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     test_main()
 |