diff options
| author | Gael Pasgrimaud <gael@gawel.org> | 2021-08-26 14:24:05 +0200 |
|---|---|---|
| committer | Gael Pasgrimaud <gael@gawel.org> | 2021-08-26 14:24:05 +0200 |
| commit | 26e73903c8b4b5591608918afc8a2d0933c1848d (patch) | |
| tree | 05ad17ff38643c374b6f6e8a7bd17ca459968200 /webtest | |
| parent | a25740bc410675766b9247fcaf78295de190069b (diff) | |
| download | webtest-26e73903c8b4b5591608918afc8a2d0933c1848d.tar.gz | |
Fixed #236: app.lxml support xml responses with encoding declaration
Diffstat (limited to 'webtest')
| -rw-r--r-- | webtest/response.py | 14 |
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): |
