mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +03:00
Use unidecode to handle unicode characters in constant names (#1080)
This commit is contained in:
parent
55a03ba716
commit
9a19447213
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
|
||||||
# Adapted from this response in Stackoverflow
|
# Adapted from this response in Stackoverflow
|
||||||
|
@ -18,4 +19,4 @@ def to_snake_case(name):
|
||||||
|
|
||||||
|
|
||||||
def to_const(string):
|
def to_const(string):
|
||||||
return re.sub(r"[\W|^]+", "_", string).upper() # noqa
|
return re.sub(r"[\W|^]+", "_", unidecode(string)).upper()
|
||||||
|
|
|
@ -21,3 +21,7 @@ def test_camel_case():
|
||||||
|
|
||||||
def test_to_const():
|
def test_to_const():
|
||||||
assert to_const('snakes $1. on a "#plane') == "SNAKES_1_ON_A_PLANE"
|
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"
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -86,6 +86,7 @@ setup(
|
||||||
"graphql-core>=3.0.0,<4",
|
"graphql-core>=3.0.0,<4",
|
||||||
"graphql-relay>=3.0.0,<4",
|
"graphql-relay>=3.0.0,<4",
|
||||||
"aniso8601>=6,<9",
|
"aniso8601>=6,<9",
|
||||||
|
"unidecode>=1.1.1,<2",
|
||||||
],
|
],
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
extras_require={"test": tests_require, "dev": dev_requires},
|
extras_require={"test": tests_require, "dev": dev_requires},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user