"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zaqar/transport/wsgi/utils.py" between
zaqar-9.0.0.tar.gz and zaqar-10.0.0.tar.gz

About: OpenStack Zaqar is a multi-tenant cloud messaging and notification service for web and mobile developers.
The "Ussuri" series (latest release).

utils.py  (zaqar-9.0.0):utils.py  (zaqar-10.0.0)
skipping to change at line 70 skipping to change at line 70
except utils.MalformedJSON as ex: except utils.MalformedJSON as ex:
LOG.debug(ex) LOG.debug(ex)
description = _(u'Request body could not be parsed.') description = _(u'Request body could not be parsed.')
raise errors.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
except utils.OverflowedJSONInteger as ex: except utils.OverflowedJSONInteger as ex:
LOG.debug(ex) LOG.debug(ex)
description = _(u'JSON contains integer that is too large.') description = _(u'JSON contains integer that is too large.')
raise errors.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
except Exception as ex: except Exception:
# Error while reading from the network/server # Error while reading from the network/server
LOG.exception(ex)
description = _(u'Request body could not be read.') description = _(u'Request body could not be read.')
LOG.exception(description)
raise errors.HTTPServiceUnavailable(description) raise errors.HTTPServiceUnavailable(description)
def sanitize(document, spec=None, doctype=JSONObject): def sanitize(document, spec=None, doctype=JSONObject):
"""Validates a document and drops undesired fields. """Validates a document and drops undesired fields.
:param document: A dict to verify according to `spec`. :param document: A dict to verify according to `spec`.
:param spec: (Default None) Iterable describing expected fields, :param spec: (Default None) Iterable describing expected fields,
yielding tuples with the form of: yielding tuples with the form of:
(field_name, value_type, default_value) (field_name, value_type, default_value)
skipping to change at line 189 skipping to change at line 189
"""Reads request body, raising an exception if it is not JSON. """Reads request body, raising an exception if it is not JSON.
:param req: The request object to read from :param req: The request object to read from
:type req: falcon.Request :type req: falcon.Request
:return: a dictionary decoded from the JSON stream :return: a dictionary decoded from the JSON stream
:rtype: dict :rtype: dict
:raises HTTPBadRequestBody: if JSON could not be parsed :raises HTTPBadRequestBody: if JSON could not be parsed
""" """
try: try:
return utils.read_json(req.stream, req.content_length) return utils.read_json(req.stream, req.content_length)
except (utils.MalformedJSON, utils.OverflowedJSONInteger) as ex: except (utils.MalformedJSON, utils.OverflowedJSONInteger):
LOG.exception(ex) message = 'JSON could not be parsed.'
raise errors.HTTPBadRequestBody( LOG.exception(message)
'JSON could not be parsed.' raise errors.HTTPBadRequestBody(message)
)
# TODO(cpp-cabrera): generalize this # TODO(cpp-cabrera): generalize this
def validate(validator, document): def validate(validator, document):
"""Verifies a document against a schema. """Verifies a document against a schema.
:param validator: a validator to use to check validity :param validator: a validator to use to check validity
:type validator: jsonschema.Draft4Validator :type validator: jsonschema.Draft4Validator
:param document: document to check :param document: document to check
:type document: dict :type document: dict
:raises HTTPBadRequestBody: if the request is invalid :raises HTTPBadRequestBody: if the request is invalid
 End of changes. 4 change blocks. 
7 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)