From 8d9a3826facc7f828265d5dbd036db863bfb4fc2 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sat, 8 Jan 2011 23:22:30 +0100 Subject: encoding fix --- module/plugins/Plugin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'module/plugins/Plugin.py') diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 0453206cd..880b9e211 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -278,7 +278,7 @@ class Plugin(object): return result - def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}): + def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}, utf8=False): """ returns the content loaded """ if self.pyfile.abort: raise Abort @@ -286,6 +286,12 @@ class Plugin(object): if no_post_encode: self.log.warning("Deprecated argument no_post_encode: %s" % no_post_encode) res = self.req.load(url, get, post, ref, cookies, just_header) + + if utf8: + #@TODO parse header and decode automatically when needed + res = res.decode("utf8", "replace") + + if self.core.debug: from inspect import currentframe frame = currentframe() @@ -294,11 +300,11 @@ class Plugin(object): f = open(join("tmp", self.__name__, "%s_line%s.dump.html" % (frame.f_back.f_code.co_name, frame.f_back.f_lineno)), "wb") try: - res = res.encode("utf8") + tmp = res.encode("utf8") except: - pass + tmp = res - f.write(res) + f.write(tmp) f.close() return res -- cgit v1.2.3