diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-06-18 15:15:37 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-06-18 18:20:30 +0200 |
commit | 503cd9ed9b18fcc1bbcae17e8d2f7d38ee7018d4 (patch) | |
tree | f84467290c90f338992a848e29e1c5071cc85c90 /utils.py | |
parent | 106e930ee670f1aaaefb4ca89081d4e9ffa691d1 (diff) | |
download | clufter-503cd9ed9b18fcc1bbcae17e8d2f7d38ee7018d4.tar.gz clufter-503cd9ed9b18fcc1bbcae17e8d2f7d38ee7018d4.tar.xz clufter-503cd9ed9b18fcc1bbcae17e8d2f7d38ee7018d4.zip |
command/format: pass declared cmd context subset to Format object
This subset is declared with 'context_specs' and is being built on the
metaclass level in the top-down, extending (additive/non-subtractive)
manner (just like the set of methods is growing monotonously top-down
the hierarchy).
Currently, only 'validator_specs' (mapping protocols to the somewhat
abstract "validator spec", '' key being used as a failback) is of
interest this way, and can be used as an on-off validation toggle
on user's request (by convence, '' value stands for off state).
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -53,6 +53,27 @@ def isinstanceexcept(subj, obj, exc=()): return isinstance(subj, obj) and not isinstance(subj, exc) +def popattr(obj, what, *args): + assert len(args) < 2 + ret = getattr(obj, what, *args) + try: + delattr(obj, what) + except AttributeError: + if args: + ret = args[0] + else: + raise + return ret + + +def iterattrs(obj, skip_private=True): + """Iterate through (unbound) attributes of obj, skipping private or not""" + if skip_private: + return ((n, v) for n, v in obj.__dict__.iteritems() + if not n.startswith('__')) + return obj.__dict__.iteritems() + + def func_defaults_varnames(func, skip=0): """Using introspection, get arg defaults (dict) + all arg names (tuple) |