Fix error when logging http response with python 3

Python 3 changed the semantics of dict.items() [0], which now returns a
iterable 'view' instead of a list of tuples. This has the repercussion
that you can no longer check for membership of a key using:

    key in dict.items()

This patch simply replaces that check with a test for the key existing
in the dict itself, rather than the items.

[0] http://legacy.python.org/dev/peps/pep-3106/

Closes-Bug: 1359880

Change-Id: I7c59b0432725b660c9fa7270cde2e07bf3ea77db
This commit is contained in:
Louis Taylor
2014-08-26 18:21:47 +00:00
parent 6987295884
commit 6dda6f306f

View File

@@ -119,7 +119,7 @@ class HTTPClient(object):
status = (resp.raw.version / 10.0, resp.status_code, resp.reason) status = (resp.raw.version / 10.0, resp.status_code, resp.reason)
dump = ['\nHTTP/%.1f %s %s' % status] dump = ['\nHTTP/%.1f %s %s' % status]
headers = resp.headers.items() headers = resp.headers.items()
if 'X-Auth-Token' in headers: if 'X-Auth-Token' in resp.headers:
headers['X-Auth-Token'] = '*' * 3 headers['X-Auth-Token'] = '*' * 3
dump.extend(['%s: %s' % (k, v) for k, v in headers]) dump.extend(['%s: %s' % (k, v) for k, v in headers])
dump.append('') dump.append('')