def to_python(rule):
 namespace = {'IN': in_range_list, 'WITHIN': within_range_list, 'MOD': cldr_modulo, 'extract_operands': extract_operands}
 to_python_func = _PythonCompiler().compile
 result = ['def evaluate(n):', ' n, i, v, w, f, t = extract_operands(n)']
 for (tag, ast) in PluralRule.parse(rule).abstract:
  result.append((' if (%s): return %r' % (to_python_func(ast), str(tag))))
 result.append((' return %r' % _fallback_tag))
 code = compile('\n'.join(result), '<rule>', 'exec')
 eval(code, namespace)
 return namespace['evaluate']

def to_python ( rule ) : namespace = { 'IN' : in_range_list , 'WITHIN' : within_range_list , 'MOD' : cldr_modulo , 'extract_operands' : extract_operands } to_python_func = _PythonCompiler ( ) . compile result = [ 'def evaluate(n):' , ' n, i, v, w, f, t = extract_operands(n)' ] for ( tag , ast ) in PluralRule . parse ( rule ) . abstract : result . append ( ( ' if (%s): return %r' % ( to_python_func ( ast ) , str ( tag ) ) ) ) result . append ( ( ' return %r' % _fallback_tag ) ) code = compile ( '\n' . join ( result ) , '<rule>' , 'exec' ) eval ( code , namespace ) return namespace [ 'evaluate' ]
convert a list/dict of rules or a pluralrule object into a regular python function .