Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73485912
webcomment_washer.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jul 21, 14:21
Size
1 KB
Mime Type
text/x-python
Expires
Tue, Jul 23, 14:21 (2 d)
Engine
blob
Format
Raw Data
Handle
19206412
Attached To
R3600 invenio-infoscience
webcomment_washer.py
View Options
from
invenio.htmlutils
import
HTMLWasher
,
cfg_html_buffer_allowed_tag_whitelist
,
\
cfg_html_buffer_allowed_attribute_whitelist
class
EmailWasher
(
HTMLWasher
):
"""
Wash comments before being send by email
"""
def
handle_starttag
(
self
,
tag
,
attrs
):
"""Function called for new opening tags"""
if
tag
.
lower
()
in
self
.
allowed_tag_whitelist
:
if
tag
.
lower
()
in
[
'ul'
,
'ol'
]:
self
.
result
+=
'
\n
'
elif
tag
.
lower
()
==
'li'
:
self
.
result
+=
'* '
elif
tag
.
lower
()
==
'a'
:
for
(
attr
,
value
)
in
attrs
:
if
attr
.
lower
()
==
'href'
:
self
.
result
+=
'<'
+
value
+
'>'
+
'('
def
handle_endtag
(
self
,
tag
):
"""Function called for ending of tags"""
if
tag
.
lower
()
in
self
.
allowed_tag_whitelist
:
if
tag
.
lower
()
in
[
'li'
,
'ul'
,
'ol'
]:
self
.
result
+=
'
\n
'
elif
tag
.
lower
()
==
'a'
:
self
.
result
+=
')'
def
handle_startendtag
(
self
,
tag
,
attrs
):
"""Function called for empty tags (e.g. <br />)"""
self
.
result
+=
""
def
handle_entityref
(
self
,
name
):
"""Process a general entity reference of the form "&name;".
Return it as it is."""
if
name
==
'nbsp'
:
self
.
result
+=
' '
else
:
self
.
result
+=
'&'
+
name
+
';'
Event Timeline
Log In to Comment