forked from LBRYCommunity/lbry-sdk
enable to set max_key_fee to null via cli
This commit is contained in:
parent
1e7bec48b6
commit
32cc077e1f
2 changed files with 22 additions and 5 deletions
|
@ -148,7 +148,10 @@ class MaxKeyFee(Setting[dict]):
|
|||
|
||||
@staticmethod
|
||||
def _parse_list(l):
|
||||
assert len(l) == 2, 'Max key fee is made up of two values: "AMOUNT CURRENCY".'
|
||||
if len(l) == 1 and (l[0] == 'null' or not l[0]):
|
||||
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:
|
||||
|
@ -159,8 +162,8 @@ class MaxKeyFee(Setting[dict]):
|
|||
return {'amount': amount, 'currency': currency}
|
||||
|
||||
def deserialize(self, value):
|
||||
if value is None:
|
||||
return
|
||||
if not value:
|
||||
return None
|
||||
if isinstance(value, dict):
|
||||
return {
|
||||
'currency': value['currency'],
|
||||
|
@ -176,7 +179,7 @@ class MaxKeyFee(Setting[dict]):
|
|||
parser.add_argument(
|
||||
self.cli_name,
|
||||
help=self.doc,
|
||||
nargs=2,
|
||||
nargs='+',
|
||||
metavar=('AMOUNT', 'CURRENCY'),
|
||||
default=NOT_SET
|
||||
)
|
||||
|
@ -527,7 +530,8 @@ class Config(CLIConfig):
|
|||
"peers are not found or are slow", 2.0
|
||||
)
|
||||
max_key_fee = MaxKeyFee(
|
||||
"Don't download streams with fees exceeding this amount", {'currency': 'USD', 'amount': 50.0}
|
||||
"Don't download streams with fees exceeding this amount. When set to "
|
||||
"null, the amount is unbounded.", {'currency': 'USD', 'amount': 50.0}
|
||||
)
|
||||
|
||||
# reflector settings
|
||||
|
|
|
@ -207,6 +207,11 @@ class ConfigurationTests(unittest.TestCase):
|
|||
c.max_key_fee = None
|
||||
with open(config, 'r') as fd:
|
||||
self.assertEqual(fd.read(), 'max_key_fee: null\n')
|
||||
c = Config.create_from_arguments(
|
||||
types.SimpleNamespace(config=config)
|
||||
)
|
||||
with open(config, 'r') as fd:
|
||||
self.assertEqual(c.max_key_fee, None)
|
||||
|
||||
def test_max_key_fee_from_args(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -222,6 +227,14 @@ class ConfigurationTests(unittest.TestCase):
|
|||
c = Config.create_from_arguments(args)
|
||||
self.assertEqual(c.max_key_fee, None)
|
||||
|
||||
args = parser.parse_args(['--max-key-fee', 'null'])
|
||||
c = Config.create_from_arguments(args)
|
||||
self.assertEqual(c.max_key_fee, None)
|
||||
|
||||
args = parser.parse_args(['--max-key-fee', ''])
|
||||
c = Config.create_from_arguments(args)
|
||||
self.assertEqual(c.max_key_fee, None)
|
||||
|
||||
# set
|
||||
args = parser.parse_args(['--max-key-fee', '1.0', 'BTC'])
|
||||
c = Config.create_from_arguments(args)
|
||||
|
|
Loading…
Reference in a new issue