-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
32 lines (26 loc) · 760 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import functools
from lxml.html.clean import Cleaner
from IPython.display import display_html, IFrame
from urllib.parse import quote
def display_iframe(html, width, height):
src = 'data:text/html;charset=utf-8,' + quote(html)
return IFrame(src=src, width=width, height=height)
def display_raw(html):
cleaner = Cleaner()
cleaner.javascript = True
cleaner.style = True
html = cleaner.clean_html(html)
return display_html(html, raw=True)
def none_on_error(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception:
return None
return wrapper
def main():
pass
if __name__ == '__main__':
main()