<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> def evaluate_expressions ( expressions ) : <EOL> """<STR_LIT>""" <EOL> ( base , exps ) = parse_expression ( str ( expressions ) ) <EOL> for e in exps : <EOL> try : <EOL> base = base [ : e [ <NUM_LIT:0> ] ] + unicode ( eval ( e [ <NUM_LIT:1> ] , None , None ) ) + base [ e [ <NUM_LIT:0> ] : ] <EOL> except Exception : <EOL> base = base [ : e [ <NUM_LIT:0> ] ] + '<STR_LIT:$>' + e [ <NUM_LIT:1> ] + '<STR_LIT:$>' + base [ e [ <NUM_LIT:0> ] : ] <EOL> return base <EOL> def parse_expression ( expression ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> output = expression <EOL> result = [ ] <EOL> p = re . compile ( r'<STR_LIT>' ) <EOL> e = p . finditer ( output ) <EOL> if e : <EOL> offset = <NUM_LIT:0> <EOL> for s in e : <EOL> exp = s . group ( ) <EOL> result . append ( ( s . span ( ) [ <NUM_LIT:0> ] - offset , exp [ <NUM_LIT:1> : len ( exp ) - <NUM_LIT:1> ] ) ) <EOL> offset += s . span ( ) [ <NUM_LIT:1> ] - s . span ( ) [ <NUM_LIT:0> ] <EOL> result . reverse ( ) <EOL> output = p . sub ( '<STR_LIT>' , output ) <EOL> output . replace ( '<STR_LIT>' , '<STR_LIT:$>' ) <EOL> return ( output , result ) </s>
