aboutsummaryrefslogtreecommitdiffstats
path: root/servo/lib/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'servo/lib/utils.py')
-rw-r--r--servo/lib/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py
index 2994fb3..7d9e21c 100644
--- a/servo/lib/utils.py
+++ b/servo/lib/utils.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import json
+import html2text
import subprocess
from django.http import HttpResponse
from django.core.cache import cache
@@ -107,3 +108,19 @@ class SessionSerializer:
def loads(self, data):
return json.loads(data, cls=DjangoJSONEncoder)
+
+
+def unescape(s):
+ import HTMLParser
+ html_parser = HTMLParser.HTMLParser()
+ return html_parser.unescape(s)
+
+
+def html_to_text(s, ignore_images=False):
+ h = html2text.HTML2Text()
+ h.ignore_images = ignore_images
+ return h.handle(s)
+
+
+def gsx_to_text(s):
+ return html_to_text(unescape(s))