diff options
author | Joffrey F <joffrey@docker.com> | 2015-09-23 14:05:03 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2015-09-25 14:36:39 -0700 |
commit | 29219a278bdbcfc15c3891df651ec297e5fb47de (patch) | |
tree | ee90336c5db691d8649bf8d20ce059fb5adb2c70 /docker | |
parent | 5e331a55a8e8e10354693172dce1aa63f58ebe97 (diff) | |
download | docker-py-782-unicode-volume-paths.tar.gz |
Don't break when volume binds contain unicode characters782-unicode-volume-paths
Also includes a few unit tests for utils.convert_volume_binds
Signed-off-by: Joffrey F <joffrey@docker.com>
Diffstat (limited to 'docker')
-rw-r--r-- | docker/utils/utils.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 36edf8d..1fce137 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -242,6 +242,9 @@ def convert_volume_binds(binds): result = [] for k, v in binds.items(): + if isinstance(k, six.binary_type): + k = k.decode('utf-8') + if isinstance(v, dict): if 'ro' in v and 'mode' in v: raise ValueError( @@ -249,6 +252,10 @@ def convert_volume_binds(binds): .format(repr(v)) ) + bind = v['bind'] + if isinstance(bind, six.binary_type): + bind = bind.decode('utf-8') + if 'ro' in v: mode = 'ro' if v['ro'] else 'rw' elif 'mode' in v: @@ -256,11 +263,15 @@ def convert_volume_binds(binds): else: mode = 'rw' - result.append('{0}:{1}:{2}'.format( - k, v['bind'], mode - )) + result.append( + six.text_type('{0}:{1}:{2}').format(k, bind, mode) + ) else: - result.append('{0}:{1}:rw'.format(k, v)) + if isinstance(v, six.binary_type): + v = v.decode('utf-8') + result.append( + six.text_type('{0}:{1}:rw').format(k, v) + ) return result |