Commit ff8eafca authored by Vincent Pelletier's avatar Vincent Pelletier

caucase.http: Fix server_version encoding for py2.7 .

Work around what should be a test-only issue, where versioneer produces
a unicode object for the module's version (by decoding a json object,
whose strings become unicode objects). Python 2.7's BaseHttpServer does
not encode the response in such case, causing a test failure when writing
to wfile, set to be a BytesIO object.
I guess some magic encoding happens on a real socket, likely to ascii.
parent 35919046
......@@ -176,6 +176,17 @@ class CaucaseWSGIRequestHandler(WSGIRequestHandler):
other than stderr for log output.
"""
server_version = 'caucased ' + version.__version__
# pylint: disable=undefined-variable
if sys.version_info[0] < 3 and isinstance(server_version, unicode): # pragma: no cover
# pylint: enable=undefined-variable
# BBB: py2.7
# Unicode objects are expected in py3, but unexpected in py2.
# When running on an installed egg, versioneer returns a unicode object for
# the version, making server_version the only unicode object sent over http
# in this source. Normalise it.
# This should be a test-only issue (as tests set a BytesIO object as wfile
# in testWSGIBase) but consistency should not hurt in general.
server_version = server_version.encode('ascii')
remote_user_name = '-'
def __init__(self, *args, **kw):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment