Skip to content

Commit

Permalink
Fix #621 - unicode for python2 and python3 (#624)
Browse files Browse the repository at this point in the history
* Use six to handle unicode conversion
  • Loading branch information
jsancio authored and tamarrow committed May 24, 2016
1 parent e88bffe commit ea619b3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion cli/dcoscli/log.py
Expand Up @@ -2,6 +2,8 @@
import sys
import time

import six

from dcos import emitting, util
from dcos.errors import DCOSException

Expand Down Expand Up @@ -89,7 +91,7 @@ def _stream_files(curr_header, fn, mesos_files):
if lines:
curr_header = _output(curr_header,
len(reachable_files) > 1,
str(mesos_file),
six.text_type(mesos_file),
lines)

return curr_header, reachable_files
Expand Down
3 changes: 2 additions & 1 deletion cli/dcoscli/main.py
Expand Up @@ -4,6 +4,7 @@

import dcoscli
import docopt
import six
from dcos import constants, emitting, errors, http, subcommand, util
from dcos.errors import DCOSException
from dcoscli.subcommand import SubcommandMain, default_doc
Expand Down Expand Up @@ -127,7 +128,7 @@ def set_ssl_info_env_vars(config):
if 'core.ssl_verify' in config and (
not os.environ.get(constants.DCOS_SSL_VERIFY_ENV)):

os.environ[constants.DCOS_SSL_VERIFY_ENV] = str(
os.environ[constants.DCOS_SSL_VERIFY_ENV] = six.text_type(
config['core.ssl_verify'])

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion cli/dcoscli/marathon/main.py
Expand Up @@ -6,6 +6,7 @@
import dcoscli
import docopt
import pkg_resources
import six
from dcos import cmds, emitting, http, jsonitem, marathon, options, util
from dcos.errors import DCOSException
from dcoscli import tables
Expand Down Expand Up @@ -297,7 +298,7 @@ def _list(json_):
else:
deployments = client.get_deployments()
table = tables.app_table(apps, deployments)
output = str(table)
output = six.text_type(table)
if output:
emitter.publish(output)

Expand Down
3 changes: 2 additions & 1 deletion cli/dcoscli/node/main.py
Expand Up @@ -3,6 +3,7 @@

import dcoscli
import docopt
import six
from dcos import cmds, emitting, errors, mesos, util
from dcos.errors import DCOSException, DefaultError
from dcoscli import log, tables
Expand Down Expand Up @@ -97,7 +98,7 @@ def _list(json_):
emitter.publish(slaves)
else:
table = tables.slave_table(slaves)
output = str(table)
output = six.text_type(table)
if output:
emitter.publish(output)
else:
Expand Down
3 changes: 2 additions & 1 deletion cli/dcoscli/service/main.py
Expand Up @@ -2,6 +2,7 @@

import dcoscli
import docopt
import six
from dcos import cmds, emitting, marathon, mesos, util
from dcos.errors import DCOSException, DefaultError
from dcoscli import log, tables
Expand Down Expand Up @@ -92,7 +93,7 @@ def _service(inactive, completed, is_json):
emitter.publish([service.dict() for service in services])
else:
table = tables.service_table(services)
output = str(table)
output = six.text_type(table)
if output:
emitter.publish(output)

Expand Down
3 changes: 2 additions & 1 deletion cli/dcoscli/task/main.py
Expand Up @@ -2,6 +2,7 @@

import dcoscli
import docopt
import six
from dcos import cmds, emitting, mesos, util
from dcos.errors import DCOSException, DCOSHTTPException, DefaultError
from dcoscli import log, tables
Expand Down Expand Up @@ -94,7 +95,7 @@ def _task(fltr, completed, json_):
emitter.publish([task.dict() for task in tasks])
else:
table = tables.task_table(tasks)
output = str(table)
output = six.text_type(table)
if output:
emitter.publish(output)

Expand Down
4 changes: 2 additions & 2 deletions dcos/emitting.py
Expand Up @@ -111,7 +111,7 @@ def publish_table(emitter, objs, table_fn, json_):
emitter.publish(objs)
else:
table = table_fn(objs)
output = str(table)
output = six.text_type(table)
if output:
emitter.publish(output)

Expand Down Expand Up @@ -160,7 +160,7 @@ def _page(output, pager_command=None):
:type pager_command: str
"""

output = str(output)
output = six.text_type(output)

if pager_command is None:
pager_command = 'less -R'
Expand Down
6 changes: 4 additions & 2 deletions dcos/util.py
Expand Up @@ -431,7 +431,9 @@ def _format_validation_error(error):
message = 'Error: {}\n'.format(error_message)
if len(error.absolute_path) > 0:
message += 'Path: {}\n'.format(
'.'.join([str(path) for path in error.absolute_path]))
'.'.join(
[six.text_type(path)
for path in error.absolute_path]))
message += 'Value: {}'.format(json.dumps(error.instance))

return message
Expand Down Expand Up @@ -478,7 +480,7 @@ def create_schema(obj):
else:
raise ValueError(
'Cannot create schema with object {} of unrecognized type'
.format(str(obj)))
.format(six.text_type(obj)))


def list_to_err(errs):
Expand Down

0 comments on commit ea619b3

Please sign in to comment.