<s> class NameNotFound ( Exception ) : <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> versions = { } <EOL> original_names = { } <EOL> def get ( name ) : <EOL> version = versions . get ( name ) <EOL> if version is None : <EOL> raise NameNotFound ( name ) <EOL> else : <EOL> return "<STR_LIT>" % ( name , version ) <EOL> def fresh ( name ) : <EOL> version = versions . get ( name , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> versions [ name ] = version <EOL> if version == <NUM_LIT:1> : <EOL> ssa_name = name <EOL> else : <EOL> ssa_name = "<STR_LIT>" % ( name , version ) <EOL> original_names [ ssa_name ] = name <EOL> return ssa_name <EOL> lcase_chars = [ chr ( i + <NUM_LIT> ) for i in xrange ( <NUM_LIT> ) ] <EOL> def fresh_list ( count ) : <EOL> prefixes = lcase_chars [ : count ] <EOL> while len ( prefixes ) < count : <EOL> count -= <NUM_LIT> <EOL> prefixes += lcase_chars [ : count ] <EOL> return map ( fresh , prefixes ) <EOL> def original ( unique_name ) : <EOL> original_name = original_names . get ( unique_name ) <EOL> if original_name is None : <EOL> versions [ unique_name ] = <NUM_LIT:1> <EOL> original_names [ unique_name ] = unique_name <EOL> return unique_name <EOL> else : <EOL> return original_name <EOL> def refresh ( unique_name ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return fresh ( original ( unique_name ) ) <EOL> except NameNotFound : <EOL> return fresh ( unique_name ) <EOL> def add_prefix ( prefix , name ) : <EOL> base = original ( name ) <EOL> return fresh ( prefix + base ) </s>
