Commit 4b29fcf0 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

handle original character set.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41862 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 26894651
...@@ -164,8 +164,10 @@ class StrippingParser(HTMLParser): ...@@ -164,8 +164,10 @@ class StrippingParser(HTMLParser):
def handle_data(self, data): def handle_data(self, data):
if self.suppress: return if self.suppress: return
if data: data = escape(data)
self.result.append(escape(data)) if self.original_charset and isinstance(data, str):
data = data.decode(self.original_charset)
self.result.append(data)
def handle_charref(self, name): def handle_charref(self, name):
if self.suppress: return if self.suppress: return
...@@ -252,6 +254,8 @@ class StrippingParser(HTMLParser): ...@@ -252,6 +254,8 @@ class StrippingParser(HTMLParser):
k = len(self.rawdata) k = len(self.rawdata)
data = self.rawdata[i+9:k] data = self.rawdata[i+9:k]
j = k+3 j = k+3
if self.original_charset and isinstance(data, str):
data = data.decode(self.original_charset)
self.result.append("<![CDATA[%s]]>" % data) self.result.append("<![CDATA[%s]]>" % data)
else: else:
try: try:
...@@ -278,11 +282,10 @@ def scrubHTML(html, valid=VALID_TAGS, nasty=NASTY_TAGS, ...@@ -278,11 +282,10 @@ def scrubHTML(html, valid=VALID_TAGS, nasty=NASTY_TAGS,
default_encoding=default_encoding) default_encoding=default_encoding)
parser.feed(html) parser.feed(html)
parser.close() parser.close()
if parser.original_charset: result = parser.getResult()
result = parser.getResult().decode(parser.original_charset)\ if parser.original_charset and isinstance(result, str):
.encode(default_encoding) result = result.decode(parser.original_charset).encode(default_encoding)
return result return result
return parser.getResult()
class SafeHTML: class SafeHTML:
"""Simple transform which uses CMFDefault functions to """Simple transform which uses CMFDefault functions to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment