Python 3.4 compatibility
This commit fixes two issues, which make the client work with Python 3.4 and still being compatible with Python 2.7. The first issue is, that the command line args somehow become a Map instead of list in Python 3.4. I fixed it by explicitly making argv (sys.argv) a list. The second issue is in the httpclient.py, where the values of a http response are of type byte, which cannot be joined by join method of string. I fixed it by decoding byte to utf-8 string. Additional if statement satisfies wrong Python 3.4 test behavior. Change-Id: Ifaf03cbc5512dcbe82cfc37bc0c8471ffdbc7018 Closes-Bug: #1535821
This commit is contained in:
parent
9738b96ca7
commit
1a7a781e48
@ -167,7 +167,15 @@ class HTTPClient(object):
|
||||
# Read body into string if it isn't obviously image data
|
||||
body_str = None
|
||||
if resp.getheader('content-type', None) != 'application/octet-stream':
|
||||
body_str = ''.join([chunk for chunk in body_iter])
|
||||
# decoding byte to string is necessary for Python 3.4 compatibility
|
||||
# this issues has not been found with Python 3.4 unit tests
|
||||
# because the test creates a fake http response of type str
|
||||
# the if statement satisfies test (str) and real (bytes) behavior
|
||||
body_list = [
|
||||
chunk.decode("utf-8") if isinstance(chunk, bytes)
|
||||
else chunk for chunk in body_iter
|
||||
]
|
||||
body_str = ''.join(body_list)
|
||||
self.log_http_response(resp, body_str)
|
||||
body_iter = six.StringIO(body_str)
|
||||
else:
|
||||
|
@ -396,6 +396,10 @@ class OpenStackMagnumShell(object):
|
||||
|
||||
def main(self, argv):
|
||||
|
||||
# NOTE(Christoph Jansen): With Python 3.4 argv somehow becomes a Map.
|
||||
# This hack fixes it.
|
||||
argv = list(argv)
|
||||
|
||||
# Parse args once to find version and debug settings
|
||||
parser = self.get_base_parser()
|
||||
(options, args) = parser.parse_known_args(argv)
|
||||
|
Loading…
x
Reference in New Issue
Block a user