From 99adb981d7eddc473c929de6dd00c28be1d13bf5 Mon Sep 17 00:00:00 2001 From: Henry Baldursson Date: Fri, 4 Oct 2019 04:18:16 +0000 Subject: [PATCH 1/3] Use unidecode to handle unicode characters in constant names --- graphene/utils/str_converters.py | 3 ++- graphene/utils/tests/test_str_converters.py | 4 ++++ setup.py | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/graphene/utils/str_converters.py b/graphene/utils/str_converters.py index 216b05476..00e2196c3 100644 --- a/graphene/utils/str_converters.py +++ b/graphene/utils/str_converters.py @@ -1,4 +1,5 @@ import re +from unidecode import unidecode # Adapted from this response in Stackoverflow @@ -18,4 +19,4 @@ def to_snake_case(name): def to_const(string): - return re.sub(r"[\W|^]+", "_", string).upper() # noqa + return re.sub(r"[\W|^]+", "_", unidecode(string)).upper() # noqa diff --git a/graphene/utils/tests/test_str_converters.py b/graphene/utils/tests/test_str_converters.py index 786149d98..b11cda918 100644 --- a/graphene/utils/tests/test_str_converters.py +++ b/graphene/utils/tests/test_str_converters.py @@ -21,3 +21,7 @@ def test_camel_case(): def test_to_const(): assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE" + + +def test_to_const_unicode(): + assert to_const('Skoða þetta unicode stöff') == 'SKODA_THETTA_UNICODE_STOFF' diff --git a/setup.py b/setup.py index 58ec73456..d7077f0c9 100644 --- a/setup.py +++ b/setup.py @@ -86,6 +86,7 @@ def run_tests(self): "graphql-core>=3.0.0,<4", "graphql-relay>=3.0.0,<4", "aniso8601>=6,<9", + "unidecode>=1.1.1,<2", ], tests_require=tests_require, extras_require={"test": tests_require, "dev": dev_requires}, From 815408a6d4926ec747b8ace6a577eee21028d9d2 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Sat, 8 Feb 2020 11:10:17 +0000 Subject: [PATCH 2/3] Remove noqa comment --- graphene/utils/str_converters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene/utils/str_converters.py b/graphene/utils/str_converters.py index 00e2196c3..9ac8461f3 100644 --- a/graphene/utils/str_converters.py +++ b/graphene/utils/str_converters.py @@ -19,4 +19,4 @@ def to_snake_case(name): def to_const(string): - return re.sub(r"[\W|^]+", "_", unidecode(string)).upper() # noqa + return re.sub(r"[\W|^]+", "_", unidecode(string)).upper() From 209ac3ca8199c7a2d39644e4dd6bd6687e07cceb Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Sat, 8 Feb 2020 11:17:11 +0000 Subject: [PATCH 3/3] Fix formatting issue --- graphene/utils/tests/test_str_converters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene/utils/tests/test_str_converters.py b/graphene/utils/tests/test_str_converters.py index b11cda918..d765906c8 100644 --- a/graphene/utils/tests/test_str_converters.py +++ b/graphene/utils/tests/test_str_converters.py @@ -24,4 +24,4 @@ def test_to_const(): def test_to_const_unicode(): - assert to_const('Skoða þetta unicode stöff') == 'SKODA_THETTA_UNICODE_STOFF' + assert to_const("Skoða þetta unicode stöff") == "SKODA_THETTA_UNICODE_STOFF"