From a9734c6146b6588244406578930cd4f0a061ad4c Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 22 Aug 2017 10:43:46 +0200 Subject: fixed exceptions --- lib/.commands.py.swp | Bin 0 -> 16384 bytes lib/app.py | 4 ++-- lib/commands.py | 26 +++++++++----------------- lib/listcommands.py | 4 ++-- 4 files changed, 13 insertions(+), 21 deletions(-) create mode 100644 lib/.commands.py.swp (limited to 'lib') diff --git a/lib/.commands.py.swp b/lib/.commands.py.swp new file mode 100644 index 0000000..d80ed53 Binary files /dev/null and b/lib/.commands.py.swp differ diff --git a/lib/app.py b/lib/app.py index c5d68ec..1a74485 100644 --- a/lib/app.py +++ b/lib/app.py @@ -53,14 +53,14 @@ class Stout(Commands): else: raise KeyError except (KeyError, IndexError): - ListCommands.err('keyword') + ListCommands.err('KeyError') else: try: what = cmd[0] if what in ListCommands.commands: self.command(what, cmd) else: - ListCommands.err('keyword') + ListCommands.err('KeyError') except IndexError: pass diff --git a/lib/commands.py b/lib/commands.py index db464fe..ced0f3c 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -24,10 +24,8 @@ class Commands(object): print('Ok') elif cmd[1] is not ListCommands.commands['set']: raise KeyError - except IndexError: - ListCommands.err('wrong') - except KeyError: - ListCommands.err('keyword') + except (IndexError, KeyError) as e: + ListCommands.err(type(e).__name__) except PersonalError as e: ListCommands.err('personal', e.value) elif what == 'get': @@ -43,7 +41,7 @@ class Commands(object): else: print('nil') elif cmd[2] not in ListCommands.commands['get'][1]: #check if the word after 'i' exists - ListCommands.err('keyword') + raise KeyError else: print(co[cmd[2]]) elif cmd[1] == 'todo': @@ -63,10 +61,8 @@ class Commands(object): print(count.decode('utf-8')) else: raise KeyError - except IndexError: - ListCommands.err('wrong') - except KeyError: - ListCommands.err('keyword') + except (IndexError, KeyError) as e: + ListCommands.err(type(e).__name__) except PersonalError as e: ListCommands.err('personal', e.value) elif what == 'add': @@ -84,10 +80,8 @@ class Commands(object): print('Ok') except: raise KeyError - except IndexError: - ListCommands.err('wrong') - except KeyError: - ListCommands.err('keyword') + except (IndexError, KeyError): + ListCommands.err(type(e).__name__) elif what == 'del': try: if len(cmd) > ListCommands.info['del'][1]: @@ -105,10 +99,8 @@ class Commands(object): print('Ok') except Exception as e: print(e) - except IndexError: - ListCommands.err('wrong') - except KeyError: - ListCommands.err('keyword') + except (IndexError, KeyError) as e: + ListCommands.err(type(e).__name__) def msgFromId(value): diff --git a/lib/listcommands.py b/lib/listcommands.py index 987aeb5..869f475 100644 --- a/lib/listcommands.py +++ b/lib/listcommands.py @@ -27,9 +27,9 @@ Se utilizzato con il "flag" i, si possono visualizzare le info: get i host, get @staticmethod def err(err, info = ''): - if err == 'keyword': + if err == 'KeyError': sys.stderr.write(RED + 'keyword inesistente\n' + BLACK) - elif err == 'wrong': + elif err == 'IndexError': sys.stderr.write(RED + 'sintassi comando errata\n' + BLACK) elif err == 'personal': sys.stderr.write(RED + str(info) + '\n' + BLACK) -- cgit v1.2.3-18-g5258