Merge pull request #21 from channelcat/master

remote tracking
This commit is contained in:
7 2018-06-10 20:17:27 -07:00 committed by GitHub
commit c1222175b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 4 deletions

View File

@ -2,4 +2,4 @@ aiofiles
httptools httptools
ujson; sys_platform != "win32" and implementation_name == "cpython" ujson; sys_platform != "win32" and implementation_name == "cpython"
uvloop; sys_platform != "win32" and implementation_name == "cpython" uvloop; sys_platform != "win32" and implementation_name == "cpython"
websockets websockets>=4.0,<5.0

View File

@ -303,7 +303,8 @@ class Sanic:
await fut await fut
except (CancelledError, ConnectionClosed): except (CancelledError, ConnectionClosed):
pass pass
self.websocket_tasks.remove(fut) finally:
self.websocket_tasks.remove(fut)
await ws.close() await ws.close()
self.router.add(uri=uri, handler=websocket_handler, self.router.add(uri=uri, handler=websocket_handler,

View File

@ -78,6 +78,11 @@ class Request(dict):
self.method, self.method,
self.path) self.path)
def __bool__(self):
if self.transport:
return True
return False
@property @property
def json(self): def json(self):
if self.parsed_json is None: if self.parsed_json is None:

View File

@ -1,4 +1,5 @@
import re import re
import uuid
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from collections.abc import Iterable from collections.abc import Iterable
from functools import lru_cache from functools import lru_cache
@ -18,6 +19,8 @@ REGEX_TYPES = {
'number': (float, r'[0-9\\.]+'), 'number': (float, r'[0-9\\.]+'),
'alpha': (str, r'[A-Za-z]+'), 'alpha': (str, r'[A-Za-z]+'),
'path': (str, r'[^/].*?'), 'path': (str, r'[^/].*?'),
'uuid': (uuid.UUID, r'[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-'
r'[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}')
} }
ROUTER_CACHE_SIZE = 1024 ROUTER_CACHE_SIZE = 1024

View File

@ -60,7 +60,7 @@ requirements = [
uvloop, uvloop,
ujson, ujson,
'aiofiles>=0.3.0', 'aiofiles>=0.3.0',
'websockets>=4.0', 'websockets>=4.0,<5.0',
] ]
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
print("Installing without uJSON") print("Installing without uJSON")

View File

@ -422,6 +422,28 @@ def test_dynamic_route_regex():
assert response.status == 200 assert response.status == 200
def test_dynamic_route_uuid():
import uuid
app = Sanic('test_dynamic_route_uuid')
results = []
@app.route('/quirky/<unique_id:uuid>')
async def handler(request, unique_id):
results.append(unique_id)
return text('OK')
request, response = app.test_client.get('/quirky/123e4567-e89b-12d3-a456-426655440000')
assert response.text == 'OK'
assert type(results[0]) is uuid.UUID
request, response = app.test_client.get('/quirky/{}'.format(uuid.uuid4()))
assert response.status == 200
request, response = app.test_client.get('/quirky/non-existing')
assert response.status == 404
def test_dynamic_route_path(): def test_dynamic_route_path():
app = Sanic('test_dynamic_route_path') app = Sanic('test_dynamic_route_path')

View File

@ -12,7 +12,7 @@ deps =
pytest-cov pytest-cov
pytest-sanic pytest-sanic
pytest-sugar pytest-sugar
aiohttp>=2.3 aiohttp>=2.3,<=3.2.1
chardet<=2.3.0 chardet<=2.3.0
beautifulsoup4 beautifulsoup4
gunicorn gunicorn