add MutableMapping api
This commit is contained in:
parent
cc21abe843
commit
79e9d82058
27
sanic/app.py
27
sanic/app.py
|
@ -2,6 +2,7 @@ import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
|
from collections import MutableMapping
|
||||||
from asyncio import get_event_loop, ensure_future, CancelledError
|
from asyncio import get_event_loop, ensure_future, CancelledError
|
||||||
from collections import deque, defaultdict
|
from collections import deque, defaultdict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
@ -24,7 +25,7 @@ from sanic.views import CompositionView
|
||||||
from sanic.websocket import WebSocketProtocol, ConnectionClosed
|
from sanic.websocket import WebSocketProtocol, ConnectionClosed
|
||||||
|
|
||||||
|
|
||||||
class Sanic:
|
class Sanic(MutableMapping):
|
||||||
|
|
||||||
def __init__(self, name=None, router=None, error_handler=None,
|
def __init__(self, name=None, router=None, error_handler=None,
|
||||||
load_env=True, request_class=None,
|
load_env=True, request_class=None,
|
||||||
|
@ -56,6 +57,7 @@ class Sanic:
|
||||||
self.response_middleware = deque()
|
self.response_middleware = deque()
|
||||||
self.blueprints = {}
|
self.blueprints = {}
|
||||||
self._blueprint_order = []
|
self._blueprint_order = []
|
||||||
|
self._extensions = {}
|
||||||
self.debug = None
|
self.debug = None
|
||||||
self.sock = None
|
self.sock = None
|
||||||
self.listeners = defaultdict(list)
|
self.listeners = defaultdict(list)
|
||||||
|
@ -79,6 +81,29 @@ class Sanic:
|
||||||
'running. Not supported with `create_server` function')
|
'running. Not supported with `create_server` function')
|
||||||
return get_event_loop()
|
return get_event_loop()
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------- #
|
||||||
|
# MutableMapping
|
||||||
|
# -------------------------------------------------------------------- #
|
||||||
|
|
||||||
|
def __eq__(self, other_app):
|
||||||
|
return self is other_app
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return self._extensions[key]
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
self._extensions[key] = value
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
del self._extensions[key]
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._extensions)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self._extensions)
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
# Registration
|
# Registration
|
||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
|
|
0
tests/test_app_extensions.py
Normal file
0
tests/test_app_extensions.py
Normal file
Loading…
Reference in New Issue
Block a user