Skip to content

Commit

Permalink
Rework appcontext: don't use a defaultdict, use Headers for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Feb 24, 2019
1 parent eb045e9 commit 029a617
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion flask_rest_api/etag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _is_etag_enabled():

def _get_etag_ctx():
"""Get ETag section of AppContext"""
return get_appcontext()['etag']
return get_appcontext().setdefault('etag', {})


class EtagMixin:
Expand Down
7 changes: 4 additions & 3 deletions flask_rest_api/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Utils"""

from collections import defaultdict
from collections.abc import Mapping

from werkzeug.datastructures import Headers
Expand All @@ -26,10 +25,12 @@ def deepupdate(original, update):
def get_appcontext():
"""Return extension section from top of appcontext stack"""

# http://flask.pocoo.org/docs/0.12/extensiondev/#the-extension-code
# http://flask.pocoo.org/docs/latest/extensiondev/#the-extension-code
ctx = _app_ctx_stack.top
if not hasattr(ctx, 'flask_rest_api'):
ctx.flask_rest_api = defaultdict(dict)
ctx.flask_rest_api = {
'headers': Headers(),
}
return ctx.flask_rest_api


Expand Down

0 comments on commit 029a617

Please sign in to comment.