From 6985299c8cd3fd0e57a2ba77e66755bb838faafa Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Mon, 1 Sep 2014 14:46:18 +0200 Subject: command: make usable as a library (output as a string, etc.) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New unit test included. Signed-off-by: Jan Pokorný --- protocol.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'protocol.py') 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ý " 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 -- cgit