minor fix (when redirected path has non-ASCII char and conf.url is unicode) and bits along with pieces

This commit is contained in:
Miroslav Stampar 2012-05-14 14:06:43 +00:00
parent 595f69fa2c
commit 333f8057a5
3 changed files with 7 additions and 4 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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)