commit
c1222175b3
|
@ -2,4 +2,4 @@ aiofiles
|
|||
httptools
|
||||
ujson; sys_platform != "win32" and implementation_name == "cpython"
|
||||
uvloop; sys_platform != "win32" and implementation_name == "cpython"
|
||||
websockets
|
||||
websockets>=4.0,<5.0
|
||||
|
|
|
@ -303,7 +303,8 @@ class Sanic:
|
|||
await fut
|
||||
except (CancelledError, ConnectionClosed):
|
||||
pass
|
||||
self.websocket_tasks.remove(fut)
|
||||
finally:
|
||||
self.websocket_tasks.remove(fut)
|
||||
await ws.close()
|
||||
|
||||
self.router.add(uri=uri, handler=websocket_handler,
|
||||
|
|
|
@ -78,6 +78,11 @@ class Request(dict):
|
|||
self.method,
|
||||
self.path)
|
||||
|
||||
def __bool__(self):
|
||||
if self.transport:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
if self.parsed_json is None:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import uuid
|
||||
from collections import defaultdict, namedtuple
|
||||
from collections.abc import Iterable
|
||||
from functools import lru_cache
|
||||
|
@ -18,6 +19,8 @@ REGEX_TYPES = {
|
|||
'number': (float, r'[0-9\\.]+'),
|
||||
'alpha': (str, r'[A-Za-z]+'),
|
||||
'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
|
||||
|
|
2
setup.py
2
setup.py
|
@ -60,7 +60,7 @@ requirements = [
|
|||
uvloop,
|
||||
ujson,
|
||||
'aiofiles>=0.3.0',
|
||||
'websockets>=4.0',
|
||||
'websockets>=4.0,<5.0',
|
||||
]
|
||||
if strtobool(os.environ.get("SANIC_NO_UJSON", "no")):
|
||||
print("Installing without uJSON")
|
||||
|
|
|
@ -422,6 +422,28 @@ def test_dynamic_route_regex():
|
|||
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():
|
||||
app = Sanic('test_dynamic_route_path')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user