summaryrefslogtreecommitdiff
path: root/webtest
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2021-08-26 14:24:05 +0200
committerGael Pasgrimaud <gael@gawel.org>2021-08-26 14:24:05 +0200
commit26e73903c8b4b5591608918afc8a2d0933c1848d (patch)
tree05ad17ff38643c374b6f6e8a7bd17ca459968200 /webtest
parenta25740bc410675766b9247fcaf78295de190069b (diff)
downloadwebtest-26e73903c8b4b5591608918afc8a2d0933c1848d.tar.gz
Fixed #236: app.lxml support xml responses with encoding declaration
Diffstat (limited to 'webtest')
-rw-r--r--webtest/response.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/webtest/response.py b/webtest/response.py
index 76917c7..8c4f87e 100644
--- a/webtest/response.py
+++ b/webtest/response.py
@@ -455,7 +455,19 @@ class TestResponse(webob.Response):
if self.content_type == 'text/html':
return fromstring(self.testbody, base_url=self.request.url)
else:
- return etree.XML(self.testbody, base_url=self.request.url)
+ try:
+ return etree.XML(self.testbody, base_url=self.request.url)
+ except ValueError as e:
+ # Encoding may be declared in xml. Check the error
+ error = ' '.join(e.args)
+ expected_error = (
+ 'Unicode strings with encoding declaration '
+ 'are not supported.'
+ )
+ if error.startswith(expected_error):
+ # Use bytes
+ return etree.XML(self.body, base_url=self.request.url)
+ raise
@property
def json(self):