feat(init): Repository init
[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 # strips html from input
7 # used the kick out the junk, when parsing the inline JS objects of the Netflix homepage
8 from HTMLParser import HTMLParser
9 class MLStripper(HTMLParser):
10     def __init__(self):
11         self.reset()
12         self.fed = []
13     def handle_data(self, d):
14         self.fed.append(d)
15     def get_data(self):
16         return ''.join(self.fed)
17
18 def strip_tags(html):
19     s = MLStripper()
20     s.feed(html)
21     return s.get_data()
22
23 # Takes everything, does nothing, classic no operation function
24 def noop (**kwargs):
25     return True
26
27 # log decorator
28 def log(f, name=None):
29     if name is None:
30         name = f.func_name
31     def wrapped(*args, **kwargs):
32         that = args[0]
33         class_name = that.__class__.__name__
34         arguments = ''
35         for key, value in kwargs.iteritems():
36             if key != 'account' and key != 'credentials':
37                 arguments += ":%s = %s:" % (key, value)
38         if arguments != '':
39             that.log('"' + class_name + '::' + name + '" called with arguments ' + arguments)
40         else:
41             that.log('"' + class_name + '::' + name + '" called')
42         result = f(*args, **kwargs)
43         that.log('"' + class_name + '::' + name + '" returned: ' + str(result))
44         return result
45     wrapped.__doc__ = f.__doc__
46     return wrapped