<s> import inspect <EOL> from rpython . rlib import jit , objectmodel <EOL> from rpython . rlib . unroll import unrolling_iterable <EOL> def memoize ( f ) : <EOL> cache = { } <EOL> def wrapper ( * val ) : <EOL> if objectmodel . we_are_translated ( ) : <EOL> return f ( * val ) <EOL> lup = cache . get ( val , None ) <EOL> if lup is None : <EOL> lup = f ( * val ) <EOL> cache [ val ] = lup <EOL> return lup <EOL> wrapper . __name__ = "<STR_LIT>" % f . __name__ <EOL> return wrapper <EOL> def memoize_constructor ( cls ) : <EOL> setattr ( cls , "<STR_LIT>" , staticmethod ( memoize ( cls ) ) ) <EOL> return cls <EOL> def strip ( str ) : <EOL> return str . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def add_copy_method ( copy_method = "<STR_LIT>" ) : <EOL> def wrapper ( cls ) : <EOL> """<STR_LIT>""" <EOL> field_names = [ ] <EOL> for base in inspect . getmro ( cls ) : <EOL> if base is object : <EOL> continue <EOL> fields = getattr ( base , "<STR_LIT>" , [ ] ) <EOL> field_names . extend ( map ( strip , fields ) ) <EOL> field_names = unrolling_iterable ( field_names ) <EOL> def copy ( self ) : <EOL> result = objectmodel . instantiate ( cls ) <EOL> for attr in field_names : <EOL> val = getattr ( self , attr ) <EOL> setattr ( result , attr , val ) <EOL> return result <EOL> setattr ( cls , copy_method , copy ) <EOL> return cls <EOL> return wrapper </s>
