--- a/cubicweb/etwist/request.py Thu Nov 24 15:39:52 2016 +0100
+++ b/cubicweb/etwist/request.py Thu Nov 24 16:32:14 2016 +0100
@@ -17,8 +17,7 @@
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""Twisted request handler for CubicWeb"""
-
-
+from six import text_type
from cubicweb.web.request import CubicWebRequestBase
@@ -34,7 +33,7 @@
for key, name_stream_list in req.files.items():
for name, stream in name_stream_list:
if name is not None:
- name = unicode(name, self.encoding)
+ name = text_type(name, self.encoding)
self.form.setdefault(key, []).append((name, stream))
# 3.16.4 backward compat
if len(self.form[key]) == 1:
--- a/cubicweb/req.py Thu Nov 24 15:39:52 2016 +0100
+++ b/cubicweb/req.py Thu Nov 24 16:32:14 2016 +0100
@@ -327,9 +327,9 @@
necessary encoding / decoding. Also it's designed to quote each
part of a url path and so the '/' character will be encoded as well.
"""
- if PY2 and isinstance(value, unicode):
+ if PY2 and isinstance(value, text_type):
quoted = urlquote(value.encode(self.encoding), safe=safe)
- return unicode(quoted, self.encoding)
+ return text_type(quoted, self.encoding)
return urlquote(str(value), safe=safe)
def url_unquote(self, quoted):
@@ -340,12 +340,12 @@
"""
if PY3:
return urlunquote(quoted)
- if isinstance(quoted, unicode):
+ if isinstance(quoted, text_type):
quoted = quoted.encode(self.encoding)
try:
- return unicode(urlunquote(quoted), self.encoding)
+ return text_type(urlunquote(quoted), self.encoding)
except UnicodeDecodeError: # might occurs on manually typed URLs
- return unicode(urlunquote(quoted), 'iso-8859-1')
+ return text_type(urlunquote(quoted), 'iso-8859-1')
def url_parse_qsl(self, querystring):
"""return a list of (key, val) found in the url quoted query string"""
@@ -353,13 +353,13 @@
for key, val in parse_qsl(querystring):
yield key, val
return
- if isinstance(querystring, unicode):
+ if isinstance(querystring, text_type):
querystring = querystring.encode(self.encoding)
for key, val in parse_qsl(querystring):
try:
- yield unicode(key, self.encoding), unicode(val, self.encoding)
+ yield text_type(key, self.encoding), text_type(val, self.encoding)
except UnicodeDecodeError: # might occurs on manually typed URLs
- yield unicode(key, 'iso-8859-1'), unicode(val, 'iso-8859-1')
+ yield text_type(key, 'iso-8859-1'), text_type(val, 'iso-8859-1')
def rebuild_url(self, url, **newparams):
"""return the given url with newparams inserted. If any new params
@@ -367,7 +367,7 @@
newparams may only be mono-valued.
"""
- if PY2 and isinstance(url, unicode):
+ if PY2 and isinstance(url, text_type):
url = url.encode(self.encoding)
schema, netloc, path, query, fragment = urlsplit(url)
query = parse_qs(query)
@@ -439,7 +439,7 @@
as_string = formatters[attrtype]
except KeyError:
self.error('given bad attrtype %s', attrtype)
- return unicode(value)
+ return text_type(value)
return as_string(value, self, props, displaytime)
def format_date(self, date, date_format=None, time=False):
--- a/cubicweb/rset.py Thu Nov 24 15:39:52 2016 +0100
+++ b/cubicweb/rset.py Thu Nov 24 16:32:14 2016 +0100
@@ -20,7 +20,7 @@
from warnings import warn
-from six import PY3
+from six import PY3, text_type
from six.moves import range
from logilab.common import nullobject
@@ -375,11 +375,11 @@
return rqlstr
# sounds like we get encoded or unicode string due to a bug in as_string
if not encoded:
- if isinstance(rqlstr, unicode):
+ if isinstance(rqlstr, text_type):
return rqlstr
- return unicode(rqlstr, encoding)
+ return text_type(rqlstr, encoding)
else:
- if isinstance(rqlstr, unicode):
+ if isinstance(rqlstr, text_type):
return rqlstr.encode(encoding)
return rqlstr