Merge pull request #756 from lbryio/fix_integer_resolve

Fix error when resolving an integer
This commit is contained in:
Umpei Kay Kurokawa 2017-08-14 22:52:20 -04:00 committed by GitHub
commit 690ef15ba1
3 changed files with 21 additions and 5 deletions

View file

@ -24,6 +24,8 @@ at anytime.
* Fixed incorrect formatting of "amount" fields * Fixed incorrect formatting of "amount" fields
* Fixed handling of SIGINT, SIGTERM. * Fixed handling of SIGINT, SIGTERM.
* Fixed shutdown sequence * Fixed shutdown sequence
* Fix error when resolving an integer
*
### Deprecated ### Deprecated
* The API will no longer be served at the /lbryapi path. It will now be at the root. * The API will no longer be served at the /lbryapi path. It will now be at the root.
@ -81,7 +83,7 @@ at anytime.
### Fixed ### Fixed
* Fixed timeout behaviour when calling API command get * Fixed timeout behaviour when calling API command get
* Fixed https://github.com/lbryio/lbry/issues/765 * Fixed https://github.com/lbryio/lbry/issues/765
### Removed ### Removed
* Removed stream_info_cache.json from daemon.py * Removed stream_info_cache.json from daemon.py

View file

@ -28,12 +28,12 @@ def set_flag_vals(flag_names, parsed_args):
elif key.startswith("--"): elif key.startswith("--"):
if remove_brackets(key[2:]) not in kwargs: if remove_brackets(key[2:]) not in kwargs:
k = remove_brackets(key[2:]) k = remove_brackets(key[2:])
kwargs[k] = guess_type(arg)
elif key in flag_names: elif key in flag_names:
if remove_brackets(flag_names[key]) not in kwargs: if remove_brackets(flag_names[key]) not in kwargs:
kwargs[remove_brackets(flag_names[key])] = guess_type(arg) k = remove_brackets(flag_names[key])
elif remove_brackets(key) not in kwargs: elif remove_brackets(key) not in kwargs:
kwargs[remove_brackets(key)] = guess_type(arg) k = remove_brackets(key)
kwargs[k] = guess_type(arg, k)
return kwargs return kwargs
@ -130,9 +130,11 @@ def main():
return 1 return 1
def guess_type(x): def guess_type(x, key=None):
if not isinstance(x, (unicode, str)): if not isinstance(x, (unicode, str)):
return x return x
if key in ('uri', 'channel_name', 'name', 'file_name', 'download_directory'):
return x
if x in ('true', 'True', 'TRUE'): if x in ('true', 'True', 'TRUE'):
return True return True
if x in ('false', 'False', 'FALSE'): if x in ('false', 'False', 'FALSE'):

View file

@ -16,3 +16,15 @@ class DaemonCLITests(unittest.TestCase):
self.assertEqual(False, DaemonCLI.guess_type('false')) self.assertEqual(False, DaemonCLI.guess_type('false'))
self.assertEqual(False, DaemonCLI.guess_type('False')) self.assertEqual(False, DaemonCLI.guess_type('False'))
self.assertEqual('3', DaemonCLI.guess_type('3', key="uri"))
self.assertEqual('0.3', DaemonCLI.guess_type('0.3', key="uri"))
self.assertEqual('True', DaemonCLI.guess_type('True', key="uri"))
self.assertEqual('False', DaemonCLI.guess_type('False', key="uri"))
self.assertEqual('3', DaemonCLI.guess_type('3', key="file_name"))
self.assertEqual('3', DaemonCLI.guess_type('3', key="name"))
self.assertEqual('3', DaemonCLI.guess_type('3', key="download_directory"))
self.assertEqual('3', DaemonCLI.guess_type('3', key="channel_name"))
self.assertEqual(3, DaemonCLI.guess_type('3', key="some_other_thing"))