aboutsummaryrefslogtreecommitdiff
path: root/src/web/lib
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-10-11 12:18:07 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2016-01-26 23:46:30 +0100
commit5b7db9398abaacea241d9fcce7885457c562d7fa (patch)
treeef8982202ac7492892ba184c66c67a303c8cc795 /src/web/lib
parentassigning categories to feeds and articles (diff)
downloadnewspipe-5b7db9398abaacea241d9fcce7885457c562d7fa.tar.gz
newspipe-5b7db9398abaacea241d9fcce7885457c562d7fa.tar.bz2
newspipe-5b7db9398abaacea241d9fcce7885457c562d7fa.zip
a bit of cleaning, putting code where it belongs
Diffstat (limited to 'src/web/lib')
-rw-r--r--src/web/lib/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/web/lib/utils.py b/src/web/lib/utils.py
index aa552a12..88d24ba5 100644
--- a/src/web/lib/utils.py
+++ b/src/web/lib/utils.py
@@ -1,8 +1,10 @@
+import re
import types
import urllib
import logging
import requests
from hashlib import md5
+from flask import request, url_for
logger = logging.getLogger(__name__)
@@ -55,3 +57,17 @@ def try_get_icon_url(url, *splits):
def to_hash(text):
return md5(text.encode('utf8') if hasattr(text, 'encode') else text)\
.hexdigest()
+
+
+def clear_string(data):
+ """
+ Clear a string by removing HTML tags, HTML special caracters
+ and consecutive white spaces (more that one).
+ """
+ p = re.compile('<[^>]+>') # HTML tags
+ q = re.compile('\s') # consecutive white spaces
+ return p.sub('', q.sub(' ', data))
+
+
+def redirect_url(default='home'):
+ return request.args.get('next') or request.referrer or url_for(default)
bgstack15