From 66fcb0cc8f19564b1d8313f89d2d11f0d0a4122e Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 09:49:25 +0800 Subject: [PATCH 1/4] Add py3*-no-ext test env --- tests/test_request_data.py | 6 +++++- tox.ini | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/test_request_data.py b/tests/test_request_data.py index c874f71d..f795ff1f 100644 --- a/tests/test_request_data.py +++ b/tests/test_request_data.py @@ -2,7 +2,11 @@ import random from sanic import Sanic from sanic.response import json -from ujson import loads + +try: + from ujson import loads +except ImportError: + from json import loads def test_storage(): diff --git a/tox.ini b/tox.ini index dd940f13..498bfae4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,17 +1,23 @@ [tox] -envlist = py35, py36, flake8, check - +envlist = py35, py36, {py35,py36}-no-ext, flake8, check [travis] python = - 3.5: py35, flake8, check - 3.6: py36, flake8, check - + 3.5: py35, py35-no-ext, flake8, check + 3.6: py36, py36-no-ext, flake8, check [testenv] +usedevelop = True +setenv = + {py35,py36}-no-ext: SANIC_NO_UJSON=1 + {py35,py36}-no-ext: SANIC_NO_UVLOOP=1 deps = - -rrequirements-dev.txt - + coverage + pytest + pytest-sugar + aiohttp==1.3.5 + chardet<=2.3.0 + beautifulsoup4 commands = pytest tests {posargs} coverage erase From 7cc02e84edf7a318b43d0e0a04fd09543c9863df Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 10:11:25 +0800 Subject: [PATCH 2/4] Fix json loads bug on Python 3.5 --- sanic/request.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sanic/request.py b/sanic/request.py index 57b4773c..e590e75c 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -1,3 +1,5 @@ +import sys +import json from cgi import parse_header from collections import namedtuple from http.cookies import SimpleCookie @@ -7,7 +9,12 @@ from urllib.parse import parse_qs, urlunparse try: from ujson import loads as json_loads except ImportError: - from json import loads as json_loads + if sys.version_info[:2] == (3, 5): + def json_loads(data): + # on Python 3.5 json.loads only supports str not bytes + return json.loads(data.decode()) + else: + json_loads = json.loads from sanic.exceptions import InvalidUsage from sanic.log import log From 2f84cdd708c16c9950c67e4a2b72a62864a0d2d3 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 May 2017 10:50:13 +0800 Subject: [PATCH 3/4] Fix websocket handler bug on Python3.5 with no uvloop --- sanic/app.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sanic/app.py b/sanic/app.py index 8d846c3e..29b8c71c 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -206,7 +206,12 @@ class Sanic: def response(handler): async def websocket_handler(request, *args, **kwargs): request.app = self - protocol = request.transport.get_protocol() + try: + protocol = request.transport.get_protocol() + except AttributeError: + # On Python3.5 the Transport classes in asyncio do not + # have a get_protocol() method as in uvloop + protocol = request.transport._protocol ws = await protocol.websocket_handshake(request) # schedule the application handler From ec857d1c53e119e13783c685203ce2738266f5fe Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 17 May 2017 12:21:56 +0800 Subject: [PATCH 4/4] Drop tox-travis --- .travis.yml | 24 +++++++++++++++++++----- tox.ini | 5 ----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c58412e..d8e17093 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,24 @@ sudo: false language: python -python: -- '3.5' -- '3.6' -install: pip install tox-travis -script: tox +cache: + directories: + - $HOME/.cache/pip +matrix: + include: + - env: TOX_ENV=py35 + python: 3.5 + - env: TOX_ENV=py35-no-ext + python: 3.5 + - env: TOX_ENV=py36 + python: 3.6 + - env: TOX_ENV=py36-no-ext + python: 3.6 + - env: TOX_ENV=flake8 + python: 3.6 + - env: TOX_ENV=check + python: 3.6 +install: pip install -U tox +script: tox -e $TOX_ENV deploy: provider: pypi user: channelcat diff --git a/tox.ini b/tox.ini index 498bfae4..b391c06e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,6 @@ [tox] envlist = py35, py36, {py35,py36}-no-ext, flake8, check -[travis] -python = - 3.5: py35, py35-no-ext, flake8, check - 3.6: py36, py36-no-ext, flake8, check - [testenv] usedevelop = True setenv =