This is an archive of the discontinued Mercurial Phabricator instance.

hgweb: fix logging to use native strings as appropriate
ClosedPublic

Authored by durin42 on Oct 14 2017, 4:16 PM.

Details

Summary

Kind of a tangled mess, but now logging works in both Python 2 and 3.

no-check-commit because of the interface required by Python's HTTP

server code.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

durin42 created this revision.Oct 14 2017, 4:16 PM

I'm not crazy about not logging bytes everywhere. Why is the file-like object taking bytes in Python 2 but Unicode in Python 3? It feels like you stumbled onto an existing bug where the logging mechanism isn't encoding aware?

I'm not crazy about not logging bytes everywhere. Why is the file-like object taking bytes in Python 2 but Unicode in Python 3? It feels like you stumbled onto an existing bug where the logging mechanism isn't encoding aware?

The file-like object to which we're logging is always in bytes mode - we traffic in unicodes from the callsite of log_error and log_request because there's lots of internal wsgi bits that are unicodes, and it's easier to make the log template a native string and bounce it down to bytes on Python 3 than to try and wrap the entire WSGI universe in a bytes blanket. Does that clarify things?

yuja accepted this revision.Oct 14 2017, 11:34 PM
yuja added a subscriber: yuja.
yuja added inline comments.
mercurial/hgweb/server.py
340

Replaced this with encoding.strtolocal() since socket.error may
contain platform-native string.

This revision is now accepted and ready to land.Oct 14 2017, 11:34 PM
This revision was automatically updated to reflect the committed changes.