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 | |
parent | typo (diff) | |
download | pyload-29049ab7b25f96d4f59e4cb7b6773a52bad5576b.tar.xz |
[utils] new function: safe_format()
Diffstat (limited to 'module/plugins/internal')
-rw-r--r-- | module/plugins/internal/Account.py | 10 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 5 | ||||
-rw-r--r-- | module/plugins/internal/utils.py | 32 |
3 files changed, 37 insertions, 10 deletions
diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py index e875ecaeb..b02538c68 100644 --- a/module/plugins/internal/Account.py +++ b/module/plugins/internal/Account.py @@ -1,19 +1,18 @@ # -*- coding: utf-8 -*- -import copy import random import re import threading import time from module.plugins.internal.Plugin import Plugin, Skip -from module.plugins.internal.utils import compare_time, isiterable, lock, parse_size +from module.plugins.internal.utils import compare_time, isiterable, lock, parse_size, safe_format class Account(Plugin): __name__ = "Account" __type__ = "account" - __version__ = "0.68" + __version__ = "0.69" __status__ = "stable" __description__ = """Base account plugin""" @@ -238,10 +237,7 @@ class Account(Plugin): self.syncback() - safe_info = copy.copy(self.info) - safe_info['login'] = copy.deepcopy(self.info['login']) #@Note: safe_info['login'] must be deepcopied to leave self.info['login'] without changes - safe_info['login']['password'] = "**********" - self.log_debug("Account info for user `%s`: %s" % (self.user, safe_info)) + self.log_debug("Account info for user `%s`: %s" % (self.user, safe_format(self.info, self.info['login']['password']))) return self.info diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index e439dd912..bf591d482 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -20,7 +20,7 @@ from module.plugins.internal.utils import * class Plugin(object): __name__ = "Plugin" __type__ = "plugin" - __version__ = "0.60" + __version__ = "0.61" __status__ = "stable" __config__ = [] #: [("name", "type", "desc", "default")] @@ -214,7 +214,8 @@ class Plugin(object): """ if self.pyload.debug: self.log_debug("LOAD URL " + url, - *["%s=%s" % (key, "{********}" if self.__type__ == "account" and key in ("get", "post") else val) for key, val in locals().items() if key not in ("self", "url", "_[1]")]) + *["%s=%s" % (key, safe_format(val, self.info['login']['password']) if self.__type__ == "account" else val) + for key, val in locals().items() if key not in ("self", "url", "_[1]")]) url = fixurl(url, unquote=True) #: Recheck in 0.4.10 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) |