forked from mgax/agripay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
37 lines (30 loc) · 1014 Bytes
/
utils.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
33
34
35
36
37
import re, htmlentitydefs
def html_unescape(text):
# http://effbot.org/zone/re-sub.htm#unescape-html
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
# character reference
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except ValueError:
pass
else:
# named entity
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text # leave as is
return re.sub("&#?\w+;", fixup, text)
import os
import logging
LOG_FORMAT = "[%(asctime)s] %(name)s %(levelname)s %(message)s"
def set_up_logging():
stderr = logging.StreamHandler()
stderr.setFormatter(logging.Formatter(LOG_FORMAT))
logging.getLogger().addHandler(stderr)
logging.getLogger('werkzeug').setLevel(logging.INFO)