]>
jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/erepublik/erepparser.py
3 from decimal
import Decimal
, InvalidOperation
6 def check_positive_decimal(option
, opt
, value
):
9 except InvalidOperation
:
10 raise OptionValueError('option %s: invalid decimal value: %s' % (opt
, value
))
12 if d
>= 0 and d
<= 1000000:
15 raise OptionValueError('option %s: expected value (0 <= x <= 1000000), got %s instead' % (opt
, d
))
17 def check_positive_integer(option
, opt
, value
):
21 raise OptionValueError('option %s: invalid integer value: %s' % (opt
, value
))
26 raise OptionValueError('option %s: expected positive value, got %d instead' % (opt
, i
))
28 def check_rank(option
, opt
, value
):
30 return utils
.get_rank(value
)
32 raise OptionValueError('option %s: invalid rank: %s' % (opt
, value
))
34 def check_quality(option
, opt
, value
):
36 return utils
.get_quality(value
)
38 raise OptionValueError('option %s: invalid quality: %s' % (opt
, value
))
40 def check_industry(option
, opt
, value
):
42 return utils
.get_industry(value
)
44 raise OptionValueError('option %s: invalid industry: %s' % (opt
, value
))
46 def check_domain(option
, opt
, value
):
48 return utils
.get_domain(value
)
50 raise OptionValueError('option %s: invalid domain: %s' % (opt
, value
))
52 class ErepublikParserOption(Option
):
53 TYPES
= Option
.TYPES
+ ('+decimal', '+integer', 'rank', 'quality', 'wellness', 'happiness', 'industry', 'domain')
54 TYPE_CHECKER
= copy(Option
.TYPE_CHECKER
)
55 TYPE_CHECKER
['+decimal'] = check_positive_decimal
56 TYPE_CHECKER
['+integer'] = check_positive_integer
57 TYPE_CHECKER
['rank'] = check_rank
58 TYPE_CHECKER
['quality'] = check_quality
59 TYPE_CHECKER
['wellness'] = check_positive_decimal
60 TYPE_CHECKER
['happiness'] = check_positive_decimal
61 TYPE_CHECKER
['industry'] = check_industry
62 TYPE_CHECKER
['domain'] = check_domain
64 class ErepublikParserError(Exception):
65 def __init__(self
, message
):
71 class ErepublikParser(OptionParser
):
72 def error(self
, error
):
73 raise ErepublikParserError(error
)