Skip to content

Commit

Permalink
Move helper method off already too large namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Aug 19, 2016
1 parent 136a833 commit d175d49
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions flask/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
from .globals import _app_ctx_stack


def _get_data_for_json(self, cache):
# This method is defined here to not pollute the JSONMixin namespace.
getter = getattr(self, 'get_data', None)
if getter is not None:
return getter(cache=cache)
return self.data


class JSONMixin(object):
"""Common mixin for both request and response objects to provide JSON
parsing capabilities.
Expand Down Expand Up @@ -50,12 +58,6 @@ def json(self):
'json is deprecated. Use get_json() instead.'), stacklevel=2)
return self.get_json()

def _get_data_for_json(self, cache):
getter = getattr(self, 'get_data', None)
if getter is not None:
return getter(cache=cache)
return self.data

def get_json(self, force=False, silent=False, cache=True):
"""Parses the JSON request/response data and returns it. By default
this function will return ``None`` if the mimetype is not
Expand Down Expand Up @@ -84,7 +86,7 @@ def get_json(self, force=False, silent=False, cache=True):
# been encoded correctly as well.
charset = self.mimetype_params.get('charset')
try:
data = self._get_data_for_json(cache)
data = _get_data_for_json(self, cache)
if charset is not None:
rv = json.loads(data, encoding=charset)
else:
Expand Down

0 comments on commit d175d49

Please sign in to comment.