From 707330accdc65290521148fe7ca32093adeab126 Mon Sep 17 00:00:00 2001 From: ilvalle Date: Thu, 2 Jun 2016 14:57:48 +0200 Subject: [PATCH] Enabled 3.5 on travis --- .travis.yml | 5 +++-- gluon/languages.py | 8 +++++--- gluon/rewrite.py | 8 ++++---- gluon/scheduler.py | 2 +- gluon/serializers.py | 1 + gluon/template.py | 8 ++++---- gluon/tests/__init__.py | 31 ++++++++++++++++--------------- gluon/tests/test_globals.py | 12 +++++++----- requirements.txt | 1 + 9 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 requirements.txt diff --git a/.travis.yml b/.travis.yml index 06f14e47..c7b2e14e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ cache: python: - '2.7' - 'pypy' + - '3.5' install: - | @@ -24,8 +25,8 @@ install: virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION" source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate" fi - - pip install -e . - + - if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install --download-cache $HOME/.pip-cache pycrypto; fi; + - if [[ $TRAVIS_PYTHON_VERSION != '3.5' ]]; then pip install -e .; fi; before_script: - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install --download-cache $HOME/.pip-cache coverage; fi; diff --git a/gluon/languages.py b/gluon/languages.py index 3a303850..9c550865 100644 --- a/gluon/languages.py +++ b/gluon/languages.py @@ -18,7 +18,7 @@ import pkgutil import logging from cgi import escape from threading import RLock -from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode +from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode, to_bytes from gluon.portalocker import read_locked, LockedFile from gluon.utf8 import Utf8 @@ -809,7 +809,9 @@ class translator(object): if mt is not None: return mt # we did not find a translation - if message.find('##') > 0 and not '\n' in message: + if message.find(to_bytes('##')) > 0: + pass + if message.find(to_bytes('##')) > 0 and not '\n' in message: # remove comments message = message.rsplit('##', 1)[0] # guess translation same as original @@ -819,7 +821,7 @@ class translator(object): self.language_file != self.default_language_file: write_dict(self.language_file, self.t) return regex_backslash.sub( - lambda m: m.group(1).translate(ttab_in), mt) + lambda m: m.group(1).translate(ttab_in), str(mt)) def params_substitution(self, message, symbols): """ diff --git a/gluon/rewrite.py b/gluon/rewrite.py index 0bb938b1..1cedf78b 100644 --- a/gluon/rewrite.py +++ b/gluon/rewrite.py @@ -27,7 +27,7 @@ from gluon.storage import Storage, List from gluon.http import HTTP from gluon.fileutils import abspath, read_file from gluon.settings import global_settings -from gluon._compat import urllib_unquote, urllib_quote +from gluon._compat import urllib_unquote, urllib_quote, iteritems isdir = os.path.isdir isfile = os.path.isfile @@ -514,7 +514,7 @@ def load_routers(all_apps): # domains = dict() if routers.BASE.domains: - for (d, a) in routers.BASE.domains.iteritems(): + for (d, a) in iteritems(routers.BASE.domains): (domain, app) = (d.strip(':'), a.strip('/')) if ':' in domain: (domain, port) = domain.split(':') @@ -620,7 +620,7 @@ def regex_url_in(request, environ): if routes.routes_in: environ = regex_filter_in(environ) request.env.update( - (k.lower().replace('.', '_'), v) for k, v in environ.iteritems()) + (k.lower().replace('.', '_'), v) for k, v in iteritems(environ)) # ################################################## # serve if a static file @@ -1074,7 +1074,7 @@ class MapUrlIn(object): def sluggify(self): self.request.env.update( - (k.lower().replace('.', '_'), v) for k, v in self.env.iteritems()) + (k.lower().replace('.', '_'), v) for k, v in iteritems(self.env)) def update_request(self): """ diff --git a/gluon/scheduler.py b/gluon/scheduler.py index 24949946..19b4254d 100644 --- a/gluon/scheduler.py +++ b/gluon/scheduler.py @@ -9,7 +9,7 @@ Background processes made simple --------------------------------- """ from __future__ import print_function -from gluon._compat import Queue +from gluon._compat import Queue, long import os import time diff --git a/gluon/serializers.py b/gluon/serializers.py index 9cd304ff..e578fd82 100644 --- a/gluon/serializers.py +++ b/gluon/serializers.py @@ -10,6 +10,7 @@ from gluon.html import TAG, XmlComponent, xmlescape from gluon.languages import lazyT import gluon.contrib.rss2 as rss2 import json as json_parser +from gluon._compat import long have_yaml = True try: diff --git a/gluon/template.py b/gluon/template.py index 9782eed1..e6603773 100644 --- a/gluon/template.py +++ b/gluon/template.py @@ -18,7 +18,7 @@ import os import cgi import logging from re import compile, sub, escape, DOTALL -from gluon._compat import StringIO +from gluon._compat import StringIO, unicodeT try: # have web2py @@ -812,9 +812,9 @@ class DummyResponse(): self.body.write(data.xml()) else: # make it a string - if not isinstance(data, (str, unicode)): + if not isinstance(data, (str, unicodeT)): data = str(data) - elif isinstance(data, unicode): + elif isinstance(data, unicodeT): data = data.encode('utf8', 'xmlcharrefreplace') data = cgi.escape(data, True).replace("'", "'") self.body.write(data) @@ -894,7 +894,7 @@ def render(content="hello world", if not 'NOESCAPE' in context: context['NOESCAPE'] = NOESCAPE - if isinstance(content, unicode): + if isinstance(content, unicodeT): content = content.encode('utf8') # save current response class diff --git a/gluon/tests/__init__.py b/gluon/tests/__init__.py index b5c32d0a..a0d4ad30 100644 --- a/gluon/tests/__init__.py +++ b/gluon/tests/__init__.py @@ -1,28 +1,29 @@ import sys from .test_http import * -from .test_cache import * from .test_contenttype import * -from .test_compileapp import * from .test_fileutils import * from .test_globals import * -from .test_html import * -from .test_is_url import * -from .test_languages import * -from .test_router import * from .test_recfile import * -from .test_routes import * from .test_storage import * -from .test_serializers import * -from .test_template import * -from .test_validators import * -from .test_utils import * -from .test_dal import * -from .test_tools import * -from .test_appadmin import * -from .test_scheduler import * + if sys.version[:3] == '2.7': + from .test_cache import * + from .test_compileapp import * + from .test_html import * + from .test_is_url import * + from .test_languages import * + from .test_router import * + from .test_routes import * + from .test_serializers import * + from .test_template import * + from .test_validators import * + from .test_utils import * + from .test_dal import * + from .test_tools import * + from .test_appadmin import * + from .test_scheduler import * from .test_web import * from .test_contribs import * from .test_old_doctests import * diff --git a/gluon/tests/test_globals.py b/gluon/tests/test_globals.py index 736f77e1..d2336093 100644 --- a/gluon/tests/test_globals.py +++ b/gluon/tests/test_globals.py @@ -14,6 +14,7 @@ fix_sys_path(__file__) from gluon.globals import Request, Response, Session from gluon import URL +from gluon._compat import basestring def setup_clean_session(): request = Request(env={}) @@ -158,31 +159,32 @@ class testResponse(unittest.TestCase): current = setup_clean_session() current.session._fixup_before_save() cookie = str(current.response.cookies) - self.assertTrue('secure' not in cookie) + self.assertTrue('secure' not in cookie.lower()) current = setup_clean_session() current.session.secure() current.session._fixup_before_save() cookie = str(current.response.cookies) - self.assertTrue('secure' in cookie) + self.assertTrue('secure' in cookie.lower()) def test_cookies_httponly(self): current = setup_clean_session() current.session._fixup_before_save() cookie = str(current.response.cookies) - self.assertTrue('httponly' in cookie) + # cookies in PY3 have capital letters + self.assertTrue('httponly' in cookie.lower()) current = setup_clean_session() current.session.httponly_cookies = True current.session._fixup_before_save() cookie = str(current.response.cookies) - self.assertTrue('httponly' in cookie) + self.assertTrue('httponly' in cookie.lower()) current = setup_clean_session() current.session.httponly_cookies = False current.session._fixup_before_save() cookie = str(current.response.cookies) - self.assertTrue('httponly' not in cookie) + self.assertTrue('httponly' not in cookie.lower()) if __name__ == '__main__': unittest.main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..904545b4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pycrypto