Port to Python3 (closes #14159555)
Add py34 environments to tox configuration (only for CubicWeb >= 3.23).
And depend on hg version of cubicweb-pyramid since it is not currently
Python3-compatible.
--- a/pyramid_cubicweb/core.py Tue Jun 28 11:03:20 2016 +0200
+++ b/pyramid_cubicweb/core.py Thu Jul 07 14:30:32 2016 +0200
@@ -140,7 +140,7 @@
def setup_params(self, params):
self.form = {}
- for param, val in params.iteritems():
+ for param, val in params.items():
if param in self.no_script_form_params and val:
val = self.no_script_form_param(param, val)
if isinstance(val, FieldStorage) and val.file:
--- a/pyramid_cubicweb/profile.py Tue Jun 28 11:03:20 2016 +0200
+++ b/pyramid_cubicweb/profile.py Thu Jul 07 14:30:32 2016 +0200
@@ -1,8 +1,11 @@
""" Tools for profiling.
See :ref:`profiling`."""
+from __future__ import print_function
+
import cProfile
import itertools
+
from pyramid.view import view_config
@@ -53,7 +56,7 @@
finally:
profile.disable()
if not counter.next() % dump_every:
- print "Dump profile stats to %s" % filename
+ print("Dump profile stats to %s" % filename)
profile.create_stats()
profile.dump_stats(filename)
--- a/pyramid_cubicweb/resources.py Tue Jun 28 11:03:20 2016 +0200
+++ b/pyramid_cubicweb/resources.py Thu Jul 07 14:30:32 2016 +0200
@@ -1,5 +1,6 @@
"""Contains resources classes.
"""
+from six import text_type
from rql import TypeResolverException
@@ -41,7 +42,7 @@
# conflicting eid/type
raise HTTPNotFound()
else:
- rset = req.execute(st.as_string(), {'x': unicode(self.value)})
+ rset = req.execute(st.as_string(), {'x': text_type(self.value)})
return rset
--- a/pyramid_cubicweb/tests/test_bw_request.py Tue Jun 28 11:03:20 2016 +0200
+++ b/pyramid_cubicweb/tests/test_bw_request.py Thu Jul 07 14:30:32 2016 +0200
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-from StringIO import StringIO
+from io import BytesIO
import webtest
@@ -29,9 +29,9 @@
self.make_request('/', {
'CONTENT_LENGTH': 12,
'CONTENT_TYPE': 'text/plain',
- 'wsgi.input': StringIO('some content')}))
+ 'wsgi.input': BytesIO(b'some content')}))
- self.assertEqual('some content', req.content.read())
+ self.assertEqual(b'some content', req.content.read())
def test_http_scheme(self):
req = CubicWebPyramidRequest(
@@ -49,16 +49,16 @@
def test_https_prefix(self):
r = self.webapp.get('/https/')
- self.assertIn('https://', r.body)
+ self.assertIn('https://', r.text)
def test_big_content(self):
- content = 'x'*100001
+ content = b'x'*100001
req = CubicWebPyramidRequest(
self.make_request('/', {
'CONTENT_LENGTH': len(content),
'CONTENT_TYPE': 'text/plain',
- 'wsgi.input': StringIO(content)}))
+ 'wsgi.input': BytesIO(content)}))
self.assertEqual(content, req.content.read())
@@ -81,13 +81,13 @@
def test_post_files(self):
content_type, params = self.webapp.encode_multipart(
- (), (('filefield', 'aname', 'acontent'),))
+ (), (('filefield', 'aname', b'acontent'),))
req = CubicWebPyramidRequest(
self.make_request('/', POST=params, content_type=content_type))
self.assertIn('filefield', req.form)
fieldvalue = req.form['filefield']
self.assertEqual(u'aname', fieldvalue[0])
- self.assertEqual('acontent', fieldvalue[1].read())
+ self.assertEqual(b'acontent', fieldvalue[1].read())
def test_post_unicode_urlencoded(self):
params = 'arg=%C3%A9'
--- a/pyramid_cubicweb/tests/test_core.py Tue Jun 28 11:03:20 2016 +0200
+++ b/pyramid_cubicweb/tests/test_core.py Thu Jul 07 14:30:32 2016 +0200
@@ -18,7 +18,7 @@
request.cw_cnx.execute('SET U login NULL WHERE U login "anon"')
except ValidationError:
pass
- request.response.body = 'OK'
+ request.response.body = b'OK'
return request.response
--- a/requirements-test.txt Tue Jun 28 11:03:20 2016 +0200
+++ b/requirements-test.txt Thu Jul 07 14:30:32 2016 +0200
@@ -1,2 +1,1 @@
WebTest
-cubicweb-pyramid
--- a/setup.py Tue Jun 28 11:03:20 2016 +0200
+++ b/setup.py Thu Jul 07 14:30:32 2016 +0200
@@ -27,6 +27,7 @@
include_package_data=True,
zip_safe=False,
install_requires=[
+ 'six',
'pyramid >= 1.5.0',
'waitress >= 0.8.9',
'cubicweb >= 3.19.3',
--- a/tox.ini Tue Jun 28 11:03:20 2016 +0200
+++ b/tox.ini Thu Jul 07 14:30:32 2016 +0200
@@ -1,9 +1,11 @@
[tox]
-envlist = py27-{release,dev,compat}
+envlist = py27-{release,dev,compat},py34-{release,dev}
[testenv]
sitepackages = true
-deps =
+deps =
+ py27: cubicweb-pyramid
+ py34: hg+http://hg.logilab.org/review/cubes/pyramid@4808ab6b1c9c#egg=cubicweb-pyramid
-rrequirements-test.txt
pytest
compat: hg+http://hg.logilab.org/master/cubicweb@3.22#egg=cubicweb