Commit 6cff1af5 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

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.
parent 0459094d9728
......@@ -140,7 +140,7 @@ class CubicWebPyramidRequest(CubicWebRequestBase):
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:
......
""" 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 @@ def wsgi_profile(app, filename='program.prof', dump_every=50):
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)
......
"""Contains resources classes.
"""
from six import text_type
from rql import TypeResolverException
......@@ -41,7 +42,7 @@ class EntityResource(object):
# 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
......
# -*- coding: utf-8 -*-
from StringIO import StringIO
from io import BytesIO
import webtest
......@@ -29,9 +29,9 @@ class WSGIAppTest(PyramidCWTest):
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 @@ class WSGIAppTest(PyramidCWTest):
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 @@ class WSGIAppTest(PyramidCWTest):
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'
......
......@@ -18,7 +18,7 @@ def put_in_uncommitable_state(request):
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
......
......@@ -27,6 +27,7 @@ setup(
include_package_data=True,
zip_safe=False,
install_requires=[
'six',
'pyramid >= 1.5.0',
'waitress >= 0.8.9',
'cubicweb >= 3.19.3',
......
[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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment