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/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 diff --git a/sanic/request.py b/sanic/request.py index 69307222..660fe6cb 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 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..b391c06e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,17 +1,18 @@ [tox] -envlist = py35, py36, flake8, check - - -[travis] -python = - 3.5: py35, flake8, check - 3.6: py36, flake8, check - +envlist = py35, py36, {py35,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