<s> __credits__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> class ContainerError ( Exception ) : <EOL> pass <EOL> class CannotReadError ( ContainerError ) : <EOL> pass <EOL> class CannotWriteError ( ContainerError ) : <EOL> pass <EOL> class Passthrough ( object ) : <EOL> """<STR_LIT>""" <EOL> _reserved = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> TypeName = "<STR_LIT>" <EOL> Info = None <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( Passthrough , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> def _load_if_needed ( self ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def __getattr__ ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> if attr in super ( Passthrough , self ) . __getattribute__ ( '<STR_LIT>' ) : <EOL> return super ( Passthrough , self ) . __getattribute__ ( attr ) <EOL> self . _load_if_needed ( ) <EOL> return getattr ( self . _object , attr ) <EOL> def __setattr__ ( self , attr , val ) : <EOL> """<STR_LIT>""" <EOL> if attr in super ( Passthrough , self ) . __getattribute__ ( '<STR_LIT>' ) : <EOL> return super ( Passthrough , self ) . __setattr__ ( attr , val ) <EOL> self . _load_if_needed ( ) <EOL> setattr ( self . _object , attr , val ) <EOL> def __hasattr__ ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> if attr in super ( Passthrough , self ) . __getattribute__ ( '<STR_LIT>' ) : <EOL> return True <EOL> self . _load_if_needed ( ) <EOL> return hasattr ( self . _object , attr ) <EOL> class PassthroughIO ( Passthrough ) : <EOL> _reserved = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> TypeName = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( PassthroughIO , self ) . __init__ ( * args , ** kwargs ) <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( PassthroughIO , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . _object = None <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( PassthroughIO , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . InPath = None <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( PassthroughIO , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . OutPath = None <EOL> def _load_if_needed ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _object is None : <EOL> if self . InPath is not None : <EOL> self . _object = self . _reader ( self , self . InPath ) <EOL> else : <EOL> raise CannotReadError ( "<STR_LIT>" ) <EOL> def read ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _object is None : <EOL> if self . InPath is None : <EOL> raise CannotReadError ( "<STR_LIT>" ) <EOL> self . _object = self . _reader ( self , self . InPath ) <EOL> def write ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _object is None : <EOL> self . _read ( ) <EOL> if self . _object is not None : <EOL> if self . OutPath is None : <EOL> raise CannotWriteError ( "<STR_LIT>" ) <EOL> self . _writer ( self , self . OutPath ) <EOL> self . _object = None <EOL> class PassthroughRead ( PassthroughIO ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( PassthroughRead , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> else : <EOL> raise ContainerError ( "<STR_LIT>" ) <EOL> super ( PassthroughRead , self ) . __init__ ( * args , ** kwargs ) <EOL> class PassthroughWrite ( PassthroughIO ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> super ( PassthroughWrite , self ) . __setattr__ ( '<STR_LIT>' , kwargs [ '<STR_LIT>' ] ) <EOL> else : <EOL> raise ContainerError ( "<STR_LIT>" ) <EOL> super ( PassthroughWrite , self ) . __init__ ( * args , ** kwargs ) <EOL> class DelayRead ( PassthroughRead ) : <EOL> """<STR_LIT>""" <EOL> TypeName = "<STR_LIT>" <EOL> class DelayWrite ( PassthroughWrite ) : <EOL> """<STR_LIT>""" <EOL> TypeName = "<STR_LIT>" <EOL> def __del__ ( self ) : <EOL> self . write ( ) <EOL> class ImmediateRead ( PassthroughRead ) : <EOL> """<STR_LIT>""" <EOL> TypeName = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ImmediateRead , self ) . __init__ ( * args , ** kwargs ) <EOL> self . read ( ) <EOL> class ImmediateWrite ( PassthroughWrite ) : <EOL> TypeName = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ImmediateWrite , self ) . __init__ ( * args , ** kwargs ) <EOL> self . write ( ) <EOL> def default_write_str ( obj , path ) : <EOL> f = open ( path , '<STR_LIT:w>' ) <EOL> f . write ( str ( obj . _object ) ) <EOL> f . close ( ) <EOL> def default_read_str ( obj , path ) : <EOL> f = open ( path ) <EOL> return f . read ( ) <EOL> def default_write_object ( obj , path ) : <EOL> f = open ( path , '<STR_LIT:w>' ) <EOL> f . write ( repr ( obj . _object ) ) <EOL> f . close ( ) <EOL> def default_read_object ( obj , path ) : <EOL> f = open ( path ) <EOL> return f . read ( ) <EOL> IOType = { '<STR_LIT>' : ImmediateRead , <EOL> '<STR_LIT>' : ImmediateWrite , <EOL> '<STR_LIT>' : DelayRead , <EOL> '<STR_LIT>' : DelayWrite } <EOL> IOLookup = { str : ( default_read_str , default_write_str ) } <EOL> def WithIO ( obj , IO_type = None , IO_lookup = None , ** kwargs ) : <EOL> if IO_type is None : <EOL> raise ContainerError ( "<STR_LIT>" ) <EOL> if IO_type not in IOType : <EOL> raise ContainerError ( "<STR_LIT>" % IO_type ) <EOL> if kwargs is None : <EOL> kwargs = { } <EOL> if IO_lookup is None : <EOL> IO_lookup = IOLookup <EOL> obj_type = obj . __class__ <EOL> kwargs [ '<STR_LIT>' ] = obj <EOL> if obj_type in IO_lookup : <EOL> reader , writer = IO_lookup [ obj_type ] <EOL> else : <EOL> reader , writer = default_read_object , default_write_object <EOL> kwargs [ '<STR_LIT>' ] = reader <EOL> kwargs [ '<STR_LIT>' ] = writer <EOL> return IOType [ IO_type ] ( ** kwargs ) <EOL> def WithoutIO ( obj , ** kwargs ) : <EOL> return obj </s>
