Esempio n. 1
0
 def _parse_list(l):
     assert len(l) == 2, 'Max key fee is made up of two values: "AMOUNT CURRENCY".'
     try:
         amount = float(l[0])
     except ValueError:
         raise AssertionError('First value in max key fee is a decimal: "AMOUNT CURRENCY"')
     currency = str(l[1]).upper()
     if currency not in CURRENCIES:
         raise InvalidCurrencyError(currency)
     return {'amount': amount, 'currency': currency}
Esempio n. 2
0
 def _parse_list(l):
     if l == ['null']:
         return None
     assert len(l) == 2, ('Max key fee is made up of either two values: '
                          '"AMOUNT CURRENCY", or "null" (to set no limit)')
     try:
         amount = float(l[0])
     except ValueError:
         raise AssertionError(
             'First value in max key fee is a decimal: "AMOUNT CURRENCY"')
     currency = str(l[1]).upper()
     if currency not in CURRENCIES:
         raise InvalidCurrencyError(currency)
     return {'amount': amount, 'currency': currency}
Esempio n. 3
0
 def validate(self, value):
     if value is not None:
         assert isinstance(value, dict) and set(value) == {'currency', 'amount'}, \
             f"Setting '{self.name}' must be a dict like \"{{'amount': 50.0, 'currency': 'USD'}}\"."
         if value["currency"] not in CURRENCIES:
             raise InvalidCurrencyError(value["currency"])