From 221eac26f90031435f709473379652fa7d4bc673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= Date: Wed, 2 Jan 2013 07:22:38 +0100 Subject: [PATCH] naturally... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- ponysay-tool.py | 8 ++++++++ ponysay.py | 24 +++++++----------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ponysay-tool.py b/ponysay-tool.py index 4f5beed1..a0854593 100755 --- a/ponysay-tool.py +++ b/ponysay-tool.py @@ -189,6 +189,8 @@ class PonysayTool(): if key in args: return args[key] if (args[key] is not None) and isinstance(args[key], list) else [args[key]] return None + def __contains__(self, key): + return key in args; stdout = sys.stdout class StringInputStream: @@ -419,6 +421,8 @@ class PonysayTool(): self.value = value def __getitem__(self, key): return [self.value] if key == self.key else None + def __contains__(self, key): + return key == self.key; class StringInputStream: def __init__(self): @@ -485,6 +489,8 @@ class PonysayTool(): if key == ('-W' if self.balloon else '-b'): return [('none' if self.balloon else None)] return None + def __contains__(self, key): + return key in ('-f', '-W', '-b'); stdout = sys.stdout class StringInputStream: def __init__(self): @@ -647,6 +653,8 @@ class PonysayTool(): if key == '-f': return [ponyfile] if key == '-W': return ['n'] return None + def __contains__(self, key): + return key in ('-f', '-W'); data = {} diff --git a/ponysay.py b/ponysay.py index f8f0bbf6..777a1d54 100755 --- a/ponysay.py +++ b/ponysay.py @@ -303,23 +303,13 @@ class Ponysay(): self.extraponydirs = self.extravtponydirs if self.linuxvt and not self.usekms else self.extraxponydirs ## Variadic variants of -f, -q &c - if args.opts['--f'] is not None: - if args.opts['-f'] is not None: args.opts['-f'] += args.opts['--f'] - else: args.opts['-f'] = args.opts['--f'] - if args.opts['++f'] is not None: - if args.opts['+f'] is not None: args.opts['+f'] += args.opts['++f'] - else: args.opts['+f'] = args.opts['++f'] - if args.opts['--q'] is not None: - if args.opts['-q'] is not None: args.opts['-q'] += args.opts['--q'] - else: args.opts['-q'] = args.opts['--q'] - # FIXME the following is how it should be done, but it freezes the program - #for sign in ('-', '+'): - # for letter in ('f', 'F', 'q', 'Q'): - # ssl = sign + sign + letter - # sl = sign + letter - # if (ssl in args.opts) and (args.opts[ssl] is not None): - # if args.opts[sl] is not None: args.opts[sl] += args.opts[ssl] - # else: args.opts[sl] = args.opts[ssl] + for sign in ('-', '+'): + for letter in ('f', 'F', 'q', 'Q'): + ssl = sign + sign + letter + sl = sign + letter + if (ssl in args.opts) and (args.opts[ssl] is not None): + if args.opts[sl] is not None: args.opts[sl] += args.opts[ssl] + else: args.opts[sl] = args.opts[ssl] ## Run modes if args.opts['-h'] is not None: args.help()