afb056f7994fa7c5a9483bd1a06ca70fad3029c8
[plugin.video.netflix.git] / resources / lib / utils.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Module: utils
4 # Created on: 13.01.2017
5
6 # Takes everything, does nothing, classic no operation function
7 def noop (**kwargs):
8     return True
9
10 # log decorator
11 def log(f, name=None):
12     if name is None:
13         name = f.func_name
14     def wrapped(*args, **kwargs):
15         that = args[0]
16         class_name = that.__class__.__name__
17         arguments = ''
18         for key, value in kwargs.iteritems():
19             if key != 'account' and key != 'credentials':
20                 arguments += ":%s = %s:" % (key, value)
21         if arguments != '':
22             that.log('"' + class_name + '::' + name + '" called with arguments ' + arguments)
23         else:
24             that.log('"' + class_name + '::' + name + '" called')
25         result = f(*args, **kwargs)
26         that.log('"' + class_name + '::' + name + '" returned: ' + str(result))
27         return result
28     wrapped.__doc__ = f.__doc__
29     return wrapped