Adding timeout to strip comments.

This commit is contained in:
Samuel Clay 2013-04-03 18:16:52 -07:00
parent 7a41b6a949
commit 4cf2085ee7

View file

@ -13,6 +13,7 @@ from django.utils.html import strip_tags as strip_tags_django
from django.conf import settings
from utils.tornado_escape import linkify as linkify_tornado
from utils.tornado_escape import xhtml_unescape as xhtml_unescape_tornado
from utils.feed_functions import timelimit, TimeoutError
from vendor import reseekfile
COMMENTS_RE = re.compile('\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>')
@ -193,6 +194,13 @@ def strip_tags(html):
return s.get_data()
def strip_comments(html_string):
try:
strip_comments_timelimit(html_string)
except TimeoutError:
return html_string
@timelimit(2)
def strip_comments_timelimit(html_string):
return COMMENTS_RE.sub('', html_string)
def strip_comments__lxml(html_string):