def parse_pattern(pattern):
if isinstance(pattern, NumberPattern):<EOL><INDENT>return pattern<EOL><DEDENT>def _match_number(pattern):<EOL><INDENT>rv = number_re.search(pattern)<EOL>if rv is None:<EOL><INDENT>raise ValueError('<STR_LIT>' % pattern)<EOL><DEDENT>return rv.groups()<EOL><DEDENT>pos_pattern = pattern<EOL>if '<STR_LIT:;>' in pattern:<EOL><INDENT>pos_pattern, neg_pattern = pattern.split('<STR_LIT:;>', <NUM_LIT:1>)<EOL>pos_prefix, number, pos_suffix = _match_number(pos_pattern)<EOL>neg_prefix, _, neg_suffix = _match_number(neg_pattern)<EOL><DEDENT>else:<EOL><INDENT>pos_prefix, number, pos_suffix = _match_number(pos_pattern)<EOL>neg_prefix = '<STR_LIT:->' + pos_prefix<EOL>neg_suffix = pos_suffix<EOL><DEDENT>if '<STR_LIT:E>' in number:<EOL><INDENT>number, exp = number.split('<STR_LIT:E>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>exp = None<EOL><DEDENT>if '<STR_LIT:@>' in number:<EOL><INDENT>if '<STR_LIT:.>' in number and '<STR_LIT:0>' in number:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if '<STR_LIT:.>' in number:<EOL><INDENT>integer, fraction = number.rsplit('<STR_LIT:.>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>integer = number<EOL>fraction = '<STR_LIT>'<EOL><DEDENT>def parse_precision(p):<EOL><INDENT>"""<STR_LIT>"""<EOL>min = max = <NUM_LIT:0><EOL>for c in p:<EOL><INDENT>if c in '<STR_LIT>':<EOL><INDENT>min += <NUM_LIT:1><EOL>max += <NUM_LIT:1><EOL><DEDENT>elif c == '<STR_LIT:#>':<EOL><INDENT>max += <NUM_LIT:1><EOL><DEDENT>elif c == '<STR_LIT:U+002C>':<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return min, max<EOL><DEDENT>int_prec = parse_precision(integer)<EOL>frac_prec = parse_precision(fraction)<EOL>if exp:<EOL><INDENT>exp_plus = exp.startswith('<STR_LIT:+>')<EOL>exp = exp.lstrip('<STR_LIT:+>')<EOL>exp_prec = parse_precision(exp)<EOL><DEDENT>else:<EOL><INDENT>exp_plus = None<EOL>exp_prec = None<EOL><DEDENT>grouping = babel.numbers.parse_grouping(integer)<EOL>return NumberPattern(pattern, (pos_prefix, neg_prefix),<EOL>(pos_suffix, neg_suffix), grouping,<EOL>int_prec, frac_prec,<EOL>exp_prec, exp_plus)<EOL>
Parse number format patterns