From 546d271210c1aff657a60044647533abd7f87cd4 Mon Sep 17 00:00:00 2001 From: Kevin Clifford Date: Tue, 7 Aug 2018 21:45:07 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Fix=20stringifying=20=CE=BB=20environmen?= =?UTF-8?q?t=20variables=20when=20using=20Python2=20(#579)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samcli/local/lambdafn/env_vars.py | 9 ++++++++- tests/unit/local/lambdafn/test_env_vars.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/samcli/local/lambdafn/env_vars.py b/samcli/local/lambdafn/env_vars.py index 6badb4b027c2..33790db10e6c 100644 --- a/samcli/local/lambdafn/env_vars.py +++ b/samcli/local/lambdafn/env_vars.py @@ -2,6 +2,8 @@ Supplies the environment variables necessary to set up Local Lambda runtime """ +import sys + class EnvironmentVariables(object): """ @@ -191,7 +193,12 @@ def _stringify_value(self, value): result = "false" # value is a scalar type like int, str which can be stringified - else: + # do not stringify unicode in Py2, Py3 str supports unicode + elif sys.version_info.major > 2: result = str(value) + elif not isinstance(value, unicode): # noqa: F821 pylint: disable=undefined-variable + result = str(value) + else: + result = value return result diff --git a/tests/unit/local/lambdafn/test_env_vars.py b/tests/unit/local/lambdafn/test_env_vars.py index 0b67355bc761..6b34ad22e9ab 100644 --- a/tests/unit/local/lambdafn/test_env_vars.py +++ b/tests/unit/local/lambdafn/test_env_vars.py @@ -325,6 +325,7 @@ def test_must_replace_non_scalar_with_blank_values(self, input): (False, "false"), (1234, "1234"), (3.14, "3.14"), + (u"mystring\xe0", u"mystring\xe0"), ("mystring", "mystring"), ]) def test_must_stringify(self, input, expected):