summaryrefslogtreecommitdiff
path: root/docker/utils
diff options
context:
space:
mode:
authorViacheslav Boiko <v.e.boyko@gmail.com>2015-11-05 11:33:16 +0100
committerViacheslav Boiko <v.e.boyko@gmail.com>2015-11-05 11:56:06 +0100
commit33305697728ec661d01eb4f596b20eae565fda42 (patch)
tree6a894031f3b3eb5d562614b3377b21587ba00138 /docker/utils
parent4a2db828b4ca02517afb6e5b33da33e2146d8b83 (diff)
parent47ab89ec2bd3bddf1221b856ffbaff333edeabb4 (diff)
downloaddocker-py-33305697728ec661d01eb4f596b20eae565fda42.tar.gz
Merge upstream branch 'master' into feature/logs_since
Signed-off-by: Viacheslav Boiko <v.e.boyko@gmail.com>
Diffstat (limited to 'docker/utils')
-rw-r--r--docker/utils/__init__.py2
-rw-r--r--docker/utils/utils.py37
2 files changed, 32 insertions, 7 deletions
diff --git a/docker/utils/__init__.py b/docker/utils/__init__.py
index 58e5877..bcbf568 100644
--- a/docker/utils/__init__.py
+++ b/docker/utils/__init__.py
@@ -3,7 +3,7 @@ from .utils import (
mkbuildcontext, tar, exclude_paths, parse_repository_tag, parse_host,
kwargs_from_env, convert_filters, datetime_to_timestamp, create_host_config,
create_container_config, parse_bytes, ping_registry, parse_env_file,
- version_lt, version_gte
+ version_lt, version_gte, decode_json_header, split_command,
) # flake8: noqa
from .types import Ulimit, LogConfig # flake8: noqa
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 36edf8d..39d0eba 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import base64
import io
import os
import os.path
@@ -66,6 +67,13 @@ def mkbuildcontext(dockerfile):
return f
+def decode_json_header(header):
+ data = base64.b64decode(header)
+ if six.PY3:
+ data = data.decode('utf-8')
+ return json.loads(data)
+
+
def tar(path, exclude=None, dockerfile=None):
f = tempfile.NamedTemporaryFile()
t = tarfile.open(mode='w', fileobj=f)
@@ -242,6 +250,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 +260,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 +271,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
@@ -654,6 +673,12 @@ def parse_env_file(env_file):
return environment
+def split_command(command):
+ if six.PY2 and not isinstance(command, six.binary_type):
+ command = command.encode('utf-8')
+ return shlex.split(command)
+
+
def create_container_config(
version, image, command, hostname=None, user=None, detach=False,
stdin_open=False, tty=False, mem_limit=None, ports=None, environment=None,
@@ -663,10 +688,10 @@ def create_container_config(
labels=None, volume_driver=None
):
if isinstance(command, six.string_types):
- command = shlex.split(str(command))
+ command = split_command(command)
if isinstance(entrypoint, six.string_types):
- entrypoint = shlex.split(str(entrypoint))
+ entrypoint = split_command(entrypoint)
if isinstance(environment, dict):
environment = [