Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-04-01 01:43:11 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-04-01 01:49:16 +0300
commitde21f07f6c192e8076ae091e8c73587411bda4fd (patch)
treef1aacbd3256fc548aeaa3f4dd7826a4953b759e2 /source/blender/python/intern/bpy_interface.c
parentbc318fc47099df92323276f849fe5a6ce9007546 (diff)
Generic check for string being a Py keyword
Driver code used incomplete list of Py keywords
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r--source/blender/python/intern/bpy_interface.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 0c3048dd9d6..b559623f619 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -899,6 +899,32 @@ static void bpy_module_free(void *UNUSED(mod))
#endif
+/**
+ * Avoids duplicating keyword list.
+ */
+bool BPY_string_is_keyword(const char *str)
+{
+ /* list is from...
+ * ", ".join(['"%s"' % kw for kw in __import__("keyword").kwlist])
+ */
+ const char *kwlist[] = {
+ "False", "None", "True",
+ "and", "as", "assert", "break",
+ "class", "continue", "def", "del", "elif", "else", "except",
+ "finally", "for", "from", "global", "if", "import", "in",
+ "is", "lambda", "nonlocal", "not", "or", "pass", "raise",
+ "return", "try", "while", "with", "yield", NULL,
+ };
+
+ for (int i = 0; kwlist[i]; i++) {
+ if (STREQ(str, kwlist[i])) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
/* EVIL, define text.c functions here... */
/* BKE_text.h */