Skip to content

Commit

Permalink
Better handles unicode in slcli for raw output
Browse files Browse the repository at this point in the history
Closes #739.
  • Loading branch information
Kevin McDonald committed Jul 8, 2016
1 parent 10600bf commit 1a2ddfa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions SoftLayer/CLI/formatting.py
Expand Up @@ -12,6 +12,7 @@

import click
import prettytable
import six

from SoftLayer.CLI import exceptions
from SoftLayer import utils
Expand Down Expand Up @@ -323,6 +324,10 @@ def __str__(self):
# If the original value is None, represent this as 'NULL'
if self.original is None:
return 'NULL'

if isinstance(self.original, six.string_types):
return str(self.original.encode('utf8'))

return str(self.original)

__repr__ = __str__
Expand Down
11 changes: 8 additions & 3 deletions SoftLayer/fixtures/SoftLayer_Account.py
@@ -1,19 +1,24 @@
# -*- coding: UTF-8 -*-

getPrivateBlockDeviceTemplateGroups = [{
'accountId': 1234,
'blockDevices': [],
'createDate': '2013-12-05T21:53:03-06:00',
'globalIdentifier': 'E6DBD73B-1651-4B28-BCBA-A11DF7C9D79E',
'id': 200,
'name': 'test_image',
'parentId': ''
'parentId': '',
'publicFlag': False,
}, {
'accountId': 1234,
'blockDevices': [],
'createDate': '2013-12-05T21:53:03-06:00',
'globalIdentifier': 'F9329795-4220-4B0A-B970-C86B950667FA',
'id': 201,
'name': 'private_image2',
'parentId': ''
# 'name': 'private_image2',
'name': u'a¬ሴ€耀',
'parentId': '',
'publicFlag': False,
}]

getVirtualGuests = [{
Expand Down
Expand Up @@ -5,15 +5,17 @@
'globalIdentifier': '0B5DEAF4-643D-46CA-A695-CECBE8832C9D',
'id': 100,
'name': 'test_image',
'parentId': ''
'parentId': '',
'publicFlag': True,
}, {
'accountId': 1234,
'blockDevices': [],
'createDate': '2013-12-05T21:53:03-06:00',
'globalIdentifier': 'EB38414C-2AB3-47F3-BBBD-56A5F689620B',
'id': 101,
'name': 'test_image2',
'parentId': ''
'parentId': '',
'publicFlag': True,
}]

getObject = IMAGES[0]
Expand Down
7 changes: 5 additions & 2 deletions SoftLayer/testing/xmlrpc.py
Expand Up @@ -59,9 +59,12 @@ def do_POST(self):
methodresponse=True)

self.send_response(200)
self.send_header("Content-type", "application/xml")
self.send_header("Content-type", "application/xml; charset=UTF-8")
self.end_headers()
self.wfile.write(response_body.encode('utf-8'))
try:
self.wfile.write(response_body.encode('utf-8'))
except UnicodeDecodeError:
self.wfile.write(response_body)

except SoftLayer.SoftLayerAPIError as ex:
self.send_response(200)
Expand Down
4 changes: 2 additions & 2 deletions tests/CLI/helper_tests.py
Expand Up @@ -88,12 +88,12 @@ def test_init(self):
item = formatting.FormattedItem('test', 'test_formatted')
self.assertEqual('test', item.original)
self.assertEqual('test_formatted', item.formatted)
self.assertEqual('test', str(item))
self.assertEqual('test', item)

item = formatting.FormattedItem('test')
self.assertEqual('test', item.original)
self.assertEqual('test', item.formatted)
self.assertEqual('test', str(item))
self.assertEqual('test', item)

def test_mb_to_gb(self):
item = formatting.mb_to_gb(1024)
Expand Down

0 comments on commit 1a2ddfa

Please sign in to comment.