Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FakeResponseWrapper.__str__ hardcodes latin-1 on Python 3 #16

Open
mgedmin opened this issue Jul 3, 2019 · 1 comment
Open

FakeResponseWrapper.__str__ hardcodes latin-1 on Python 3 #16

mgedmin opened this issue Jul 3, 2019 · 1 comment

Comments

@mgedmin
Copy link
Member

mgedmin commented Jul 3, 2019

I'm porting an application to Python 3. I have some (old) functional tests like this:

>>> print(http(b"GET /someurl HTTP/1.1"))
HTTP/1.1 200 Ok
...
<p>blah blah 360° blah blah ...

The ° is encoded in UTF-8 on disk. This works on Python 2, where everything is bytes.

On Python 3 I'm getting this problem:

    - <p>blah blah 360° blah blah
    + <p>blah blah 360° blah blah

because zope.app.wsgi.testlayer.FakeResponse.__str__ is defined, on Python 3, to return

        def __str__(self):
            return self.getOutput().decode('latin-1')

Meanwhile the Python 3 doctest module defaults to interpreting doctests as being in UTF-8 if no explicit encoding has been provided.

What can we do to make things work out of the box?

@mgedmin
Copy link
Member Author

mgedmin commented Jul 3, 2019

I'm considering self.getOutput().decode(self.response.charset or 'latin-1').

(The or 'latin-1' is because for responses that return e.g. image/png, self.response.charset will be None, and str.decode() does not like None.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant