From 8c94f8e7214d9ee0a131584e672ae83277303f2b Mon Sep 17 00:00:00 2001 From: RaNaN Date: Tue, 19 Jul 2011 21:10:04 +0200 Subject: use correct encoding header parsing --- module/network/HTTPChunk.py | 2 +- module/network/HTTPRequest.py | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 20 deletions(-) (limited to 'module/network') diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 0fee75682..431e5b15b 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -228,7 +228,7 @@ class HTTPChunk(HTTPRequest): def parseHeader(self): """parse data from recieved header""" - for orgline in self.header.splitlines(): + for orgline in self.decodeResponse(self.header).splitlines(): line = orgline.strip().lower() if line.startswith("accept-ranges") and "bytes" in line: self.p.chunkSupport = True 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 -- cgit v1.2.3