diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-09-01 14:46:18 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-09-01 14:49:08 +0200 |
commit | 6985299c8cd3fd0e57a2ba77e66755bb838faafa (patch) | |
tree | 67eeae723c23947fdda028d7df2e9df79fe5db72 /protocol.py | |
parent | 7175d05335dbed0dde0e06d5de19954b6ca47042 (diff) | |
download | clufter-6985299c8cd3fd0e57a2ba77e66755bb838faafa.tar.gz clufter-6985299c8cd3fd0e57a2ba77e66755bb838faafa.tar.xz clufter-6985299c8cd3fd0e57a2ba77e66755bb838faafa.zip |
command: make usable as a library (output as a string, etc.)
New unit test included.
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'protocol.py')
-rw-r--r-- | protocol.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/protocol.py b/protocol.py index ed0f546..46582c4 100644 --- a/protocol.py +++ b/protocol.py @@ -7,12 +7,17 @@ __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" import logging +from collections import MutableMapping + from .plugin_registry import PluginRegistry -from .utils import tuplist +from .utils import args2sgpl, tuplist from .utils_prog import cli_undecor log = logging.getLogger(__name__) +protodict = lambda x: isinstance(x, MutableMapping) and 'passin' in x +protodictval = lambda x: args2sgpl(x['passin']) if protodict(x) else x + class protocols(PluginRegistry): """Protocol registry (to be used as a metaclass for filters) @@ -40,4 +45,9 @@ class Protocol(str): return protocols.register(ret) def ensure_proto(self, value): - return value if tuplist(value) else (self, value) + work_val = protodictval(value) + work_val = work_val if tuplist(work_val) else (str(self), work_val) + if protodict(value): + value['passin'] = work_val + work_val = value + return work_val |