From 333f8057a5cc2f86c4f815cb3cec0ff2cac34941 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Mon, 14 May 2012 14:06:43 +0000 Subject: [PATCH] minor fix (when redirected path has non-ASCII char and conf.url is unicode) and bits along with pieces --- lib/core/common.py | 7 +++++-- lib/core/convert.py | 2 +- lib/request/redirecthandler.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 4e6e99e9b..954f0a8a7 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1886,7 +1886,10 @@ def getUnicode(value, encoding=None, system=False, noneToNull=False): if isinstance(value, unicode): return value elif isinstance(value, basestring): - return unicode(value, encoding or UNICODE_ENCODING, errors="replace") + try: + return unicode(value, encoding or kb.pageEncoding) + except: + return unicode(value, UNICODE_ENCODING, "replace") else: return unicode(value) # encoding ignored for non-basestring instances else: @@ -2511,7 +2514,7 @@ def openFile(filename, mode='r'): """ try: - return codecs.open(filename, mode, UNICODE_ENCODING, errors="replace") + return codecs.open(filename, mode, UNICODE_ENCODING, "replace") except IOError: errMsg = "there has been a file opening error for filename '%s'. " % filename errMsg += "Please check %s permissions on a file " % ("write" if \ diff --git a/lib/core/convert.py b/lib/core/convert.py index f94d368ec..9257d20ab 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -77,7 +77,7 @@ def urldecode(value, encoding=None): result = urllib.unquote_plus(value) if isinstance(result, str): - result = unicode(result, encoding or UNICODE_ENCODING, errors="replace") + result = unicode(result, encoding or UNICODE_ENCODING, "replace") return result diff --git a/lib/request/redirecthandler.py b/lib/request/redirecthandler.py index 0809add2d..1ddbe8c6e 100644 --- a/lib/request/redirecthandler.py +++ b/lib/request/redirecthandler.py @@ -78,7 +78,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler): redurl = self._get_header_redirect(headers) if not urlparse.urlsplit(redurl).netloc: - redurl = urlparse.urljoin(conf.url, redurl) + redurl = urlparse.urljoin(req.get_full_url(), redurl) self._infinite_loop_check(req) self._ask_redirect_choice(code, redurl)