Removing defusedxml dependency
Change-Id: I860341a15dc1092ce17babbc15c9e753c4027391
This commit is contained in:
parent
2a015f58b2
commit
e787448eea
@ -18,21 +18,17 @@ response with one formatted so the client can parse it.
|
|||||||
Based on pecan.middleware.errordocument
|
Based on pecan.middleware.errordocument
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from defusedxml import ElementTree
|
|
||||||
import json
|
import json
|
||||||
# from xml import etree as et
|
# from xml import etree as et
|
||||||
|
|
||||||
import webob
|
|
||||||
|
|
||||||
from cloudpulse.openstack.common._i18n import _
|
from cloudpulse.openstack.common._i18n import _
|
||||||
from cloudpulse.openstack.common._i18n import _LE
|
|
||||||
from cloudpulse.openstack.common import log
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ParsableErrorMiddleware(object):
|
class ParsableErrorMiddleware(object):
|
||||||
|
|
||||||
"""Replace error body with something the client can parse."""
|
"""Replace error body with something the client can parse."""
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
@ -65,23 +61,8 @@ class ParsableErrorMiddleware(object):
|
|||||||
|
|
||||||
app_iter = self.app(environ, replacement_start_response)
|
app_iter = self.app(environ, replacement_start_response)
|
||||||
if (state['status_code'] // 100) not in (2, 3):
|
if (state['status_code'] // 100) not in (2, 3):
|
||||||
req = webob.Request(environ)
|
body = [json.dumps({'error_message': '\n'.join(app_iter)})]
|
||||||
if (req.accept.best_match(['application/json', 'application/xml'])
|
state['headers'].append(('Content-Type', 'application/json'))
|
||||||
== 'application/xml'):
|
|
||||||
try:
|
|
||||||
# simple check xml is valid
|
|
||||||
body = [ElementTree.tostring(
|
|
||||||
ElementTree.fromstring('<error_message>'
|
|
||||||
+ '\n'.join(app_iter)
|
|
||||||
+ '</error_message>'))]
|
|
||||||
except ElementTree.ParseError as err:
|
|
||||||
LOG.error(_LE('Error parsing HTTP response: %s'), err)
|
|
||||||
body = ['<error_message>%s' % state['status_code']
|
|
||||||
+ '</error_message>']
|
|
||||||
state['headers'].append(('Content-Type', 'application/xml'))
|
|
||||||
else:
|
|
||||||
body = [json.dumps({'error_message': '\n'.join(app_iter)})]
|
|
||||||
state['headers'].append(('Content-Type', 'application/json'))
|
|
||||||
state['headers'].append(('Content-Length', str(len(body[0]))))
|
state['headers'].append(('Content-Length', str(len(body[0]))))
|
||||||
else:
|
else:
|
||||||
body = app_iter
|
body = app_iter
|
||||||
|
@ -20,4 +20,3 @@ python-glanceclient>=0.15.0,<0.18.0
|
|||||||
python-neutronclient>=2.4.0,<2.5.0
|
python-neutronclient>=2.4.0,<2.5.0
|
||||||
python-novaclient>=2.22.0,<2.24.0
|
python-novaclient>=2.22.0,<2.24.0
|
||||||
WSME>=0.6,<0.7
|
WSME>=0.6,<0.7
|
||||||
defusedxml>=0.4.1
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user