From d175d497e943c1d5d090c5b5e59b0c9b1a955c26 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Fri, 19 Aug 2016 21:35:25 +0200 Subject: [PATCH] Move helper method off already too large namespace --- flask/wrappers.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flask/wrappers.py b/flask/wrappers.py index cfb02272c2..a876c275c2 100644 --- a/flask/wrappers.py +++ b/flask/wrappers.py @@ -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. @@ -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 @@ -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: