<s> """<STR_LIT>""" <EOL> try : <EOL> from threading import RLock <EOL> lock = RLock ( ) <EOL> except ImportError : <EOL> lock = None <EOL> class Cache ( object ) : <EOL> def __init__ ( self ) : <EOL> self . content = { } <EOL> self . _building = { } <EOL> def getorbuild ( self , key ) : <EOL> if lock : lock . acquire ( ) <EOL> try : <EOL> try : <EOL> return self . content [ key ] <EOL> except KeyError : <EOL> if key in self . _building : <EOL> raise Exception , "<STR_LIT>" % ( <EOL> self , key ) <EOL> self . _building [ key ] = True <EOL> try : <EOL> result = self . _build ( key ) <EOL> self . content [ key ] = result <EOL> finally : <EOL> del self . _building [ key ] <EOL> self . _ready ( result ) <EOL> return result <EOL> finally : <EOL> if lock : lock . release ( ) <EOL> getorbuild . _annspecialcase_ = "<STR_LIT>" <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , len ( self . content ) ) <EOL> def _ready ( self , result ) : <EOL> pass <EOL> def _freeze_ ( self ) : <EOL> return True </s>
