]>
jfr.im git - irc/rizon/acid.git/blob - pyva/pyva/src/main/python/internets/erepparser.py
2 from decimal
import Decimal
, InvalidOperation
5 def check_positive_decimal(option
, opt
, value
):
8 except InvalidOperation
:
9 raise OptionValueError('option %s: invalid decimal value: %s' % (opt
, value
))
11 if d
>= 0 and d
<= 1000000:
14 raise OptionValueError('option %s: expected value (0 <= x <= 1000000), got %s instead' % (opt
, d
))
16 def check_positive_integer(option
, opt
, value
):
20 raise OptionValueError('option %s: invalid integer value: %s' % (opt
, value
))
25 raise OptionValueError('option %s: expected positive value, got %d instead' % (opt
, i
))
27 class ErepublikParserOption(Option
):
28 TYPES
= Option
.TYPES
+ ('+decimal', '+integer', 'rank', 'quality', 'wellness', 'happiness', 'industry', 'domain')
29 TYPE_CHECKER
= copy(Option
.TYPE_CHECKER
)
30 TYPE_CHECKER
['+decimal'] = check_positive_decimal
31 TYPE_CHECKER
['+integer'] = check_positive_integer
33 class ErepublikParserError(Exception):
34 def __init__(self
, message
):
40 class ErepublikParser(OptionParser
):
41 def error(self
, error
):
42 raise ErepublikParserError(error
)