#NEWLINE# def parse( input_string ) : #NEWLINE# #INDENT# def prop_to_dict( tokens ) : #NEWLINE# #INDENT# prop_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for token in tokens : #NEWLINE# #INDENT# prop_dict [ token . property_key ] = token . property_value #NEWLINE# #UNINDENT# return prop_dict #NEWLINE# #UNINDENT# word = Word ( ( alphas + '_' ) ) #NEWLINE# newline = Suppress ( '\n' ) #NEWLINE# colon = Suppress ( ':' ) #NEWLINE# arrow = Suppress ( '->' ) #NEWLINE# key = word . setResultsName ( 'property_key' ) #NEWLINE# value = Word ( ( ( ( alphas + alphas8bit ) + nums ) + '_@.+()%' ) ) . setResultsName ( 'property_value' ) #NEWLINE# field_property = Group ( ( ( key + colon ) + value ) ) . setResultsName ( 'field_property' ) #NEWLINE# field_type = oneOf ( 'CharField EmailField PasswordField SubmitField' ) . setResultsName ( 'field_type' ) #NEWLINE# field_name = word . setResultsName ( 'field_name' ) #NEWLINE# field = Group ( ( ( ( ( field_name + colon ) + field_type ) + Optional ( ( arrow + OneOrMore ( field_property ) ) ) . setParseAction ( prop_to_dict ) ) + newline ) ) . setResultsName ( 'form_field' ) #NEWLINE# form_name = word . setResultsName ( 'form_name' ) #NEWLINE# form = ( ( form_name + newline ) + OneOrMore ( field ) . setResultsName ( 'fields' ) ) #NEWLINE# return form . parseString ( input_string )