# HG changeset patch # User František Kučera # Date 1544832169 -3600 # Node ID 6a178b86d048751e0e03a9bb435dc9abda13a9d4 # Parent 7a91400b84c2f6a49a32264f2049048e9630e8c6 better regex, avoid Python keyword name collisions: WHERE = type == "btrfs" or a_pass == "1" other usage: WHERE = type == "btrfs" or a_pass == "1"; r[0] = "TROLL!!!" diff -r 7a91400b84c2 -r 6a178b86d048 src/PythonHandler.h --- a/src/PythonHandler.h Sat Dec 15 00:44:04 2018 +0100 +++ b/src/PythonHandler.h Sat Dec 15 01:02:49 2018 +0100 @@ -48,8 +48,8 @@ class PythonHandler : public RelationalReaderStringHadler { private: - const wregex ATTRIBUTE_NAMES_ALLOWED = wregex(L"[a-zA-Z0-9_]"); - const wregex ATTRIBUTE_NAMES_DISALLOWED = wregex(L"WHERE|and|or|[0-9_].*"); // TODO: more keywords + const wregex ATTRIBUTE_NAMES_ALLOWED = wregex(L"[a-zA-Z0-9_]+"); + const wregex ATTRIBUTE_NAMES_DISALLOWED = wregex(L"WHERE|[0-9_].*|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"); // Python keywords from: import keyword; keyword.kwlist shared_ptr relationalWriter; @@ -128,7 +128,8 @@ PyObject* pyValue = PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()); PyList_SetItem(pyRecord, i, pyValue); string_t attributeName = currentWriterMetadata[i].attributeName; - if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED) && !regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) { + if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED)) { + if (regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) attributeName = L"a_" + attributeName; PyDict_SetItemString(pyDict, convertor.to_bytes(attributeName).c_str(), pyValue); } }