Merge "Clean up pecan Request patching"

This commit is contained in:
Zuul 2019-12-16 19:34:33 +00:00 committed by Gerrit Code Review
commit e7558b6c5c

View File

@ -13,9 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from inspect import ismethod
from inspect import getargspec
import six import six
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
import pecan.core import pecan.core
@ -35,25 +32,18 @@ class Request(pecan.core.Request):
We add this method to ease future XML support, so the main code We add this method to ease future XML support, so the main code
is not hardcoded to call pecans "request.json" method. is not hardcoded to call pecans "request.json" method.
""" """
if self.content_type in JSON_TYPES: if self.content_type not in JSON_TYPES:
raise exceptions.UnsupportedContentType(
'Content-type must be application/json')
try: try:
json_dict = jsonutils.load(self.body_file) json_dict = jsonutils.load(self.body_file)
if json_dict is None: if json_dict is None:
# NOTE(kiall): Somehow, json.load(fp) is returning None. # NOTE(kiall): Somehow, json.load(fp) is returning None.
raise exceptions.EmptyRequestBody('Request Body is empty') raise exceptions.EmptyRequestBody('Request Body is empty')
return json_dict return json_dict
except ValueError as valueError: except ValueError as e:
if len(self.body) == 0 or self.body is None: if not self.body:
raise exceptions.EmptyRequestBody('Request Body is empty') raise exceptions.EmptyRequestBody('Request Body is empty')
else: else:
raise exceptions.InvalidJson(six.text_type(valueError)) raise exceptions.InvalidJson(six.text_type(e))
else:
raise exceptions.UnsupportedContentType(
'Content-type must be application/json')
__init__ = pecan.core.Pecan.__base__.__init__
if not ismethod(__init__) or 'request_cls' not in getargspec(__init__).args:
# only attempt to monkey patch `pecan.Request` in older versions of pecan;
# newer versions support specifying a custom request implementation in the
# `pecan.core.Pecan` constructor via the `request_cls` argument
pecan.core.Request = Request