commit
c1222175b3
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -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")
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user