Merge "Clean up pecan Request patching"
This commit is contained in:
commit
e7558b6c5c
@ -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:
|
||||||
try:
|
|
||||||
json_dict = jsonutils.load(self.body_file)
|
|
||||||
if json_dict is None:
|
|
||||||
# NOTE(kiall): Somehow, json.load(fp) is returning None.
|
|
||||||
raise exceptions.EmptyRequestBody('Request Body is empty')
|
|
||||||
return json_dict
|
|
||||||
except ValueError as valueError:
|
|
||||||
if len(self.body) == 0 or self.body is None:
|
|
||||||
raise exceptions.EmptyRequestBody('Request Body is empty')
|
|
||||||
else:
|
|
||||||
raise exceptions.InvalidJson(six.text_type(valueError))
|
|
||||||
else:
|
|
||||||
raise exceptions.UnsupportedContentType(
|
raise exceptions.UnsupportedContentType(
|
||||||
'Content-type must be application/json')
|
'Content-type must be application/json')
|
||||||
|
|
||||||
__init__ = pecan.core.Pecan.__base__.__init__
|
try:
|
||||||
if not ismethod(__init__) or 'request_cls' not in getargspec(__init__).args:
|
json_dict = jsonutils.load(self.body_file)
|
||||||
# only attempt to monkey patch `pecan.Request` in older versions of pecan;
|
if json_dict is None:
|
||||||
# newer versions support specifying a custom request implementation in the
|
# NOTE(kiall): Somehow, json.load(fp) is returning None.
|
||||||
# `pecan.core.Pecan` constructor via the `request_cls` argument
|
raise exceptions.EmptyRequestBody('Request Body is empty')
|
||||||
pecan.core.Request = Request
|
return json_dict
|
||||||
|
except ValueError as e:
|
||||||
|
if not self.body:
|
||||||
|
raise exceptions.EmptyRequestBody('Request Body is empty')
|
||||||
|
else:
|
||||||
|
raise exceptions.InvalidJson(six.text_type(e))
|
||||||
|
Loading…
Reference in New Issue
Block a user