mirror of https://github.com/docker/docs.git
Fix unicode in environment variables for python2.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
6f78271b82
commit
ae47435425
|
@ -1,3 +1,4 @@
|
||||||
|
import codecs
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -455,6 +456,8 @@ def parse_environment(environment):
|
||||||
|
|
||||||
|
|
||||||
def split_env(env):
|
def split_env(env):
|
||||||
|
if isinstance(env, six.binary_type):
|
||||||
|
env = env.decode('utf-8')
|
||||||
if '=' in env:
|
if '=' in env:
|
||||||
return env.split('=', 1)
|
return env.split('=', 1)
|
||||||
else:
|
else:
|
||||||
|
@ -477,7 +480,7 @@ def env_vars_from_file(filename):
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
raise ConfigurationError("Couldn't find env file: %s" % filename)
|
raise ConfigurationError("Couldn't find env file: %s" % filename)
|
||||||
env = {}
|
env = {}
|
||||||
for line in open(filename, 'r'):
|
for line in codecs.open(filename, 'r', 'utf-8'):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and not line.startswith('#'):
|
if line and not line.startswith('#'):
|
||||||
k, v = split_env(line)
|
k, v = split_env(line)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
FILE_DEF=F1
|
FILE_DEF=bär
|
||||||
FILE_DEF_EMPTY=
|
FILE_DEF_EMPTY=
|
||||||
ENV_DEF
|
ENV_DEF
|
||||||
NO_DEF
|
NO_DEF
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: utf-8
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ class CLITestCase(unittest.TestCase):
|
||||||
command.run(mock_project, {
|
command.run(mock_project, {
|
||||||
'SERVICE': 'service',
|
'SERVICE': 'service',
|
||||||
'COMMAND': None,
|
'COMMAND': None,
|
||||||
'-e': ['BAR=NEW', 'OTHER=THREE'],
|
'-e': ['BAR=NEW', 'OTHER=bär'.encode('utf-8')],
|
||||||
'--user': None,
|
'--user': None,
|
||||||
'--no-deps': None,
|
'--no-deps': None,
|
||||||
'--allow-insecure-ssl': None,
|
'--allow-insecure-ssl': None,
|
||||||
|
@ -114,7 +115,7 @@ class CLITestCase(unittest.TestCase):
|
||||||
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
|
_, _, call_kwargs = mock_client.create_container.mock_calls[0]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
call_kwargs['environment'],
|
call_kwargs['environment'],
|
||||||
{'FOO': 'ONE', 'BAR': 'NEW', 'OTHER': 'THREE'})
|
{'FOO': 'ONE', 'BAR': 'NEW', 'OTHER': u'bär'})
|
||||||
|
|
||||||
def test_run_service_with_restart_always(self):
|
def test_run_service_with_restart_always(self):
|
||||||
command = TopLevelCommand()
|
command = TopLevelCommand()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: utf-8
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
@ -894,7 +895,12 @@ class EnvTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
service_dict['environment'],
|
service_dict['environment'],
|
||||||
{'FILE_DEF': 'F1', 'FILE_DEF_EMPTY': '', 'ENV_DEF': 'E3', 'NO_DEF': ''},
|
{
|
||||||
|
'FILE_DEF': u'bär',
|
||||||
|
'FILE_DEF_EMPTY': '',
|
||||||
|
'ENV_DEF': 'E3',
|
||||||
|
'NO_DEF': ''
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
|
@pytest.mark.xfail(IS_WINDOWS_PLATFORM, reason='paths use slash')
|
||||||
|
|
Loading…
Reference in New Issue