diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-07-19 21:10:04 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-07-19 21:10:04 +0200 |
commit | 8c94f8e7214d9ee0a131584e672ae83277303f2b (patch) | |
tree | b43da702fe8888883d18eaf622e9a170d4e4410b /module/network/HTTPRequest.py | |
parent | fix in unrar plugin (diff) | |
download | pyload-8c94f8e7214d9ee0a131584e672ae83277303f2b.tar.xz |
use correct encoding header parsing
Diffstat (limited to 'module/network/HTTPRequest.py')
-rw-r--r-- | module/network/HTTPRequest.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index 4dd41674c..ed320562d 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -205,7 +205,7 @@ class HTTPRequest(): def decodeResponse(self, rep): """ decode with correct encoding, relies on header """ header = self.header.splitlines() - encoding = None + encoding = "utf8" # default encoding for line in header: line = line.lower().replace(" ", "") @@ -214,27 +214,22 @@ class HTTPRequest(): continue none, delemiter, charset = line.rpartition("charset=") - if not delemiter: - encoding = "utf8" - else: + if delemiter: charset = charset.split(";") if charset: encoding = charset[0] - else: - encoding = "utf8" - - if encoding: - try: - #self.log.debug("Decoded %s" % encoding ) - decoder = getincrementaldecoder(encoding)("replace") - rep = decoder.decode(rep, True) - - #TODO: html_unescape as default - - except LookupError: - self.log.debug("No Decoder foung for %s" % encoding) - except Exception: - self.log.debug("Error when decoding string from %s." % encoding) + + try: + #self.log.debug("Decoded %s" % encoding ) + decoder = getincrementaldecoder(encoding)("replace") + rep = decoder.decode(rep, True) + + #TODO: html_unescape as default + + except LookupError: + self.log.debug("No Decoder foung for %s" % encoding) + except Exception: + self.log.debug("Error when decoding string from %s." % encoding) return rep |