<s> import string , itertools <EOL> def strlist ( items , bracket = None , sep = '<STR_LIT:U+002CU+0020>' , form = repr ) : <EOL> '<STR_LIT>' <EOL> body = sep . join ( map ( form , items ) ) <EOL> if bracket : <EOL> open , close = bracket <EOL> return open + body + close <EOL> else : <EOL> return body <EOL> class Environment : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , * chained ) : <EOL> self . maps = [ dict ( ) ] + list ( chained ) <EOL> def lookup ( self , key ) : <EOL> for M in self . maps : <EOL> if key in M : return M [ key ] <EOL> raise KeyError , "<STR_LIT>" % key <EOL> def has_key ( self , key ) : <EOL> for M in self . maps : <EOL> if key in M : return True <EOL> return False <EOL> def __len__ ( self ) : return sum ( [ M . __len__ ( ) for M in self . maps ] ) <EOL> def __getitem__ ( self , key ) : return self . lookup ( key ) <EOL> def __setitem__ ( self , key , value ) : self . maps [ <NUM_LIT:0> ] [ key ] = value <EOL> def __contains__ ( self , key ) : return self . has_key ( key ) <EOL> def __iter__ ( self ) : <EOL> return itertools . chain ( * [ M . __iter__ ( ) for M in self . maps ] ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' + repr ( self . maps ) + '<STR_LIT:)>' <EOL> def iterkeys ( self ) : <EOL> return self . __iter__ ( ) <EOL> def begin_scope ( self ) : self . maps = [ dict ( ) ] + self . maps <EOL> def end_scope ( self ) : self . maps . pop ( <NUM_LIT:0> ) <EOL> def update ( self , E , ** F ) : self . maps [ <NUM_LIT:0> ] . update ( E , ** F ) <EOL> def resolve ( name , env ) : <EOL> """<STR_LIT>""" <EOL> t = name <EOL> while t in env : <EOL> t = env [ t ] <EOL> return t <EOL> def resolution_map ( names , env ) : <EOL> """<STR_LIT>""" <EOL> return dict ( zip ( names , [ resolve ( n , env ) for n in names ] ) ) <EOL> def name_supply ( stems = string . ascii_lowercase , drop_zero = True ) : <EOL> """<STR_LIT>""" <EOL> k = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> for a in stems : <EOL> yield a + str ( k ) if ( k or not drop_zero ) else a <EOL> k = k + <NUM_LIT:1> <EOL> def name_list ( length , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return list ( itertools . islice ( name_supply ( ** kwargs ) , length ) ) </s>
