zopefoundation / zope.publisher

Map requests from HTTP/WebDAV clients, web browsers, XML-RPC and FTP clients onto Python objects
Other
3 stars 12 forks source link

setStatus(b'OK') broken on Python 3 #52

Open mgedmin opened 4 years ago

mgedmin commented 4 years ago

I happened to be looking at http.py because its use of basestring on Python 3 intrigued me. I think I discovered a bug, or at least an inconsistency in setStatus: https://github.com/zopefoundation/zope.publisher/blob/69902a756c425bac12b73c19323c46d9ef671411/src/zope/publisher/http.py#L695-L707

This checks if status is a basestring (defined as (str, bytes) on Python 3), then looks it up in the status_codes dict. The dict is initialized by https://github.com/zopefoundation/zope.publisher/blob/69902a756c425bac12b73c19323c46d9ef671411/src/zope/publisher/http.py#L182-L198

which puts int and str keys in the global, but no bytestring keys.

On Python 2 u'ok' == b'ok', so you can look up either byte or unicode strings. On Python 3 that's no longer true.

I don't know if we want to support byte-strings as statuses, but if we don't, we should ... actually I no longer care about this issue.