<s> import pickle <EOL> import io <EOL> import collections <EOL> from test import support <EOL> from test . pickletester import AbstractPickleTests <EOL> from test . pickletester import AbstractPickleModuleTests <EOL> from test . pickletester import AbstractPersistentPicklerTests <EOL> from test . pickletester import AbstractPicklerUnpicklerObjectTests <EOL> from test . pickletester import AbstractDispatchTableTests <EOL> from test . pickletester import BigmemPickleTests <EOL> try : <EOL> import _pickle <EOL> has_c_implementation = True <EOL> except ImportError : <EOL> has_c_implementation = False <EOL> class PickleTests ( AbstractPickleModuleTests ) : <EOL> pass <EOL> class PyPicklerTests ( AbstractPickleTests ) : <EOL> pickler = pickle . _Pickler <EOL> unpickler = pickle . _Unpickler <EOL> def dumps ( self , arg , proto = None ) : <EOL> f = io . BytesIO ( ) <EOL> p = self . pickler ( f , proto ) <EOL> p . dump ( arg ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> return bytes ( f . read ( ) ) <EOL> def loads ( self , buf , ** kwds ) : <EOL> f = io . BytesIO ( buf ) <EOL> u = self . unpickler ( f , ** kwds ) <EOL> return u . load ( ) <EOL> class InMemoryPickleTests ( AbstractPickleTests , BigmemPickleTests ) : <EOL> pickler = pickle . _Pickler <EOL> unpickler = pickle . _Unpickler <EOL> def dumps ( self , arg , protocol = None ) : <EOL> return pickle . dumps ( arg , protocol ) <EOL> def loads ( self , buf , ** kwds ) : <EOL> return pickle . loads ( buf , ** kwds ) <EOL> class PyPersPicklerTests ( AbstractPersistentPicklerTests ) : <EOL> pickler = pickle . _Pickler <EOL> unpickler = pickle . _Unpickler <EOL> def dumps ( self , arg , proto = None ) : <EOL> class PersPickler ( self . pickler ) : <EOL> def persistent_id ( subself , obj ) : <EOL> return self . persistent_id ( obj ) <EOL> f = io . BytesIO ( ) <EOL> p = PersPickler ( f , proto ) <EOL> p . dump ( arg ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> return f . read ( ) <EOL> def loads ( self , buf , ** kwds ) : <EOL> class PersUnpickler ( self . unpickler ) : <EOL> def persistent_load ( subself , obj ) : <EOL> return self . persistent_load ( obj ) <EOL> f = io . BytesIO ( buf ) <EOL> u = PersUnpickler ( f , ** kwds ) <EOL> return u . load ( ) <EOL> class PyPicklerUnpicklerObjectTests ( AbstractPicklerUnpicklerObjectTests ) : <EOL> pickler_class = pickle . _Pickler <EOL> unpickler_class = pickle . _Unpickler <EOL> class PyDispatchTableTests ( AbstractDispatchTableTests ) : <EOL> pickler_class = pickle . _Pickler <EOL> def get_dispatch_table ( self ) : <EOL> return pickle . dispatch_table . copy ( ) <EOL> class PyChainDispatchTableTests ( AbstractDispatchTableTests ) : <EOL> pickler_class = pickle . _Pickler <EOL> def get_dispatch_table ( self ) : <EOL> return collections . ChainMap ( { } , pickle . dispatch_table ) <EOL> if has_c_implementation : <EOL> class CPicklerTests ( PyPicklerTests ) : <EOL> pickler = _pickle . Pickler <EOL> unpickler = _pickle . Unpickler <EOL> class CPersPicklerTests ( PyPersPicklerTests ) : <EOL> pickler = _pickle . Pickler <EOL> unpickler = _pickle . Unpickler <EOL> class CDumpPickle_LoadPickle ( PyPicklerTests ) : <EOL> pickler = _pickle . Pickler <EOL> unpickler = pickle . _Unpickler <EOL> class DumpPickle_CLoadPickle ( PyPicklerTests ) : <EOL> pickler = pickle . _Pickler <EOL> unpickler = _pickle . Unpickler <EOL> class CPicklerUnpicklerObjectTests ( AbstractPicklerUnpicklerObjectTests ) : <EOL> pickler_class = _pickle . Pickler <EOL> unpickler_class = _pickle . Unpickler <EOL> def test_issue18339 ( self ) : <EOL> unpickler = self . unpickler_class ( io . BytesIO ( ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> unpickler . memo = object <EOL> with self . assertRaises ( ValueError ) : <EOL> unpickler . memo = { - <NUM_LIT:1> : None } <EOL> unpickler . memo = { <NUM_LIT:1> : None } <EOL> class CDispatchTableTests ( AbstractDispatchTableTests ) : <EOL> pickler_class = pickle . Pickler <EOL> def get_dispatch_table ( self ) : <EOL> return pickle . dispatch_table . copy ( ) <EOL> class CChainDispatchTableTests ( AbstractDispatchTableTests ) : <EOL> pickler_class = pickle . Pickler <EOL> def get_dispatch_table ( self ) : <EOL> return collections . ChainMap ( { } , pickle . dispatch_table ) <EOL> def test_main ( ) : <EOL> tests = [ PickleTests , PyPicklerTests , PyPersPicklerTests , <EOL> PyDispatchTableTests , PyChainDispatchTableTests ] <EOL> if has_c_implementation : <EOL> tests . extend ( [ CPicklerTests , CPersPicklerTests , <EOL> CDumpPickle_LoadPickle , DumpPickle_CLoadPickle , <EOL> PyPicklerUnpicklerObjectTests , <EOL> CPicklerUnpicklerObjectTests , <EOL> CDispatchTableTests , CChainDispatchTableTests , <EOL> InMemoryPickleTests ] ) <EOL> support . run_unittest ( * tests ) <EOL> support . run_doctest ( pickle ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
