diff options
author | GammaC0de <nitzo2001@yahoo.com> | 2015-12-27 02:09:56 +0100 |
---|---|---|
committer | GammaC0de <nitzo2001@yahoo.com> | 2015-12-27 02:09:56 +0100 |
commit | 29049ab7b25f96d4f59e4cb7b6773a52bad5576b (patch) | |
tree | f957e7e270ec443cc734b663002bcbd55bb24d64 /module/plugins/internal/utils.py | |
parent | typo (diff) | |
download | pyload-29049ab7b25f96d4f59e4cb7b6773a52bad5576b.tar.xz |
[utils] new function: safe_format()
Diffstat (limited to 'module/plugins/internal/utils.py')
-rw-r--r-- | module/plugins/internal/utils.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/module/plugins/internal/utils.py b/module/plugins/internal/utils.py index 1fdbaf279..02077cffd 100644 --- a/module/plugins/internal/utils.py +++ b/module/plugins/internal/utils.py @@ -30,7 +30,7 @@ except ImportError: class utils(object): __name__ = "utils" __type__ = "plugin" - __version__ = "0.08" + __version__ = "0.09" __status__ = "stable" __pattern__ = r'^unmatchable$' @@ -71,6 +71,36 @@ def format_size(value): return "%.2f %s" % (size, sizes[steps]) +def safe_format(value, unsafe): + """ + Returns the content of value omitting sensitive information + + Args: + value: value to format + unsafe: string or list: sensitive word(s) to remove + """ + if isinstance(value, basestring): + if isinstance(unsafe, basestring): + return "'%s'" % ("**********" if value == unsafe else value) + + elif isinstance(unsafe, list): + return "'%s'" % ("**********" if value in unsafe else value) + + elif isinstance(value, dict): + return "{%s}" % ", ".join("'%s': %s" % (k, safe_format(v, unsafe)) for k, v in value.iteritems()) + + elif isinstance(value, list): + return "[%s]" % ", ".join("%s" % safe_format(v, unsafe) for v in value) + + elif isinstance(value, tuple): + return "(%s)" % ", ".join("%s" % safe_format(v, unsafe) for v in value) + + elif isinstance(value, set): + return "set([%s])" % ", ".join("%s" % safe_format(v, unsafe) for v in value) + + return repr(value) + + def compare_time(start, end): start = map(int, start) end = map(int, end) |