<s> """<STR_LIT>""" <EOL> import re <EOL> import keyword <EOL> from templates import templates <EOL> class Builder ( object ) : <EOL> def __init__ ( self , outfilename ) : <EOL> """<STR_LIT>""" <EOL> self . filename = outfilename <EOL> self . stocklist = [ ] <EOL> self . preamble = [ ] <EOL> self . body = [ ] <EOL> self . preamble . append ( templates [ '<STR_LIT>' ] . substitute ( ) ) <EOL> def write ( self ) : <EOL> """<STR_LIT>""" <EOL> with open ( self . filename , '<STR_LIT:w>' ) as outfile : <EOL> [ outfile . write ( element ) for element in self . preamble ] <EOL> [ outfile . write ( element ) for element in self . body ] <EOL> def add_stock ( self , identifier , expression , initial_condition ) : <EOL> """<STR_LIT>""" <EOL> self . body . append ( templates [ '<STR_LIT>' ] . substitute ( identifier = identifier , <EOL> expression = expression , <EOL> initial_condition = initial_condition ) ) <EOL> self . stocklist . append ( identifier ) <EOL> def add_flaux ( self , identifier , expression , doc = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> docstring = ( '<STR_LIT>' + <EOL> '<STR_LIT>' . join ( doc . split ( '<STR_LIT:\n>' ) ) ) <EOL> self . body . append ( templates [ '<STR_LIT>' ] . substitute ( identifier = identifier , <EOL> expression = expression , <EOL> docstring = docstring ) ) <EOL> def add_lookup ( self , identifier , valid_range , copair_list ) : <EOL> """<STR_LIT>""" <EOL> xs , ys = zip ( * copair_list ) <EOL> xs_str = str ( list ( xs ) ) <EOL> ys_str = str ( list ( ys ) ) <EOL> self . body . append ( templates [ '<STR_LIT>' ] . substitute ( identifier = identifier , <EOL> xs_str = xs_str , <EOL> ys_str = ys_str ) ) <EOL> def make_python_identifier ( string ) : <EOL> """<STR_LIT>""" <EOL> string = string . lower ( ) <EOL> string = string . strip ( ) <EOL> string = string . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> string = re . sub ( '<STR_LIT>' , '<STR_LIT>' , string ) <EOL> string = re . sub ( '<STR_LIT>' , '<STR_LIT>' , string ) <EOL> if string in keyword . kwlist : <EOL> string += '<STR_LIT>' <EOL> return string </s>
