diff options
| -rw-r--r-- | webtest/forms.py | 6 | ||||
| -rw-r--r-- | webtest/response.py | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/webtest/forms.py b/webtest/forms.py index 9ff0a17..16f5637 100644 --- a/webtest/forms.py +++ b/webtest/forms.py @@ -400,7 +400,11 @@ class Form(object): def __init__(self, response, text, parser_features='html.parser'): self.response = response self.text = text - self.html = BeautifulSoup(self.text, parser_features) + if response and response.charset: + self.html = BeautifulSoup(self.text, parser_features, + from_encoding=response.charset) + else: + self.html = BeautifulSoup(self.text, parser_features) attrs = self.html('form')[0].attrs self.action = attrs.get('action', '') diff --git a/webtest/response.py b/webtest/response.py index 3952079..186ac47 100644 --- a/webtest/response.py +++ b/webtest/response.py @@ -359,7 +359,7 @@ class TestResponse(webob.Response): raise TypeError( "The only keyword argument allowed is 'no'") for s in strings: - if not s in self: + if s not in self: print_stderr("Actual response (no %r):" % s) print_stderr(str(self)) raise IndexError( @@ -426,7 +426,11 @@ class TestResponse(webob.Response): raise AttributeError( "Not an HTML response body (content-type: %s)" % self.content_type) - soup = BeautifulSoup(self.testbody, self.parser_features) + if self.charset: + soup = BeautifulSoup(self.testbody, self.parser_features, + from_encoding=self.charset) + else: + soup = BeautifulSoup(self.testbody, self.parser_features) return soup @property @@ -484,7 +488,7 @@ class TestResponse(webob.Response): from lxml.html import fromstring except ImportError: # pragma: no cover fromstring = etree.HTML - ## FIXME: would be nice to set xml:base, in some fashion + # FIXME: would be nice to set xml:base, in some fashion if self.content_type == 'text/html': return fromstring(self.testbody, base_url=self.request.url) else: |
