@cryptotaxi247 / netdata-1 / commits / 80f343991

python.d logger: unicode_str handle TypeError (#7645)

* collection.py: unicode_str handle TypeError

Ilya Mashchenko committed Dec 31, 2019 at 11:32 UTC 80f3439917393c8ec12a4951c0d3e1b4cc013433
1 file changed +10 -1
collectors/python.d.plugin/python_modules/bases/collection.py
+10 -1
@@ -23,10 +23,11 @@ def run_and_exit(func):
23 def wrapper(*args, **kwargs):
24 func(*args, **kwargs)
25 exit(1)
26 +
27 return wrapper
28
29
29 -def on_try_except_finally(on_except=(None, ), on_finally=(None, )):
30 +def on_try_except_finally(on_except=(None,), on_finally=(None,)):
31 except_func = on_except[0]
32 finally_func = on_finally[0]
33
@@ -40,7 +41,9 @@ def on_try_except_finally(on_except=(None, ), on_finally=(None, )):
41 finally:
42 if finally_func:
43 finally_func(*on_finally[1:])
44 +
45 return wrapper
46 +
47 return decorator
48
49
@@ -49,6 +52,7 @@ def static_vars(**kwargs):
52 for k in kwargs:
53 setattr(func, k, kwargs[k])
54 return func
55 +
56 return decorate
57
58
@@ -94,9 +98,14 @@ def unicode_str(arg):
98 :param arg:
99 :return: <str>
100 """
101 + # TODO: fix
102 try:
103 + # https://github.com/netdata/netdata/issues/7613
104 if isinstance(arg, unicode):
105 return arg
106 return unicode(arg, errors='ignore')
107 + # https://github.com/netdata/netdata/issues/7642
108 + except TypeError:
109 + return unicode(arg)
110 except NameError:
111 return str(arg)