equal
deleted
inserted
replaced
46 using namespace relpipe::reader; |
46 using namespace relpipe::reader; |
47 using namespace relpipe::reader::handlers; |
47 using namespace relpipe::reader::handlers; |
48 |
48 |
49 class PythonHandler : public RelationalReaderStringHadler { |
49 class PythonHandler : public RelationalReaderStringHadler { |
50 private: |
50 private: |
51 const wregex ATTRIBUTE_NAMES_ALLOWED = wregex(L"[a-zA-Z0-9_]"); |
51 const wregex ATTRIBUTE_NAMES_ALLOWED = wregex(L"[a-zA-Z0-9_]+"); |
52 const wregex ATTRIBUTE_NAMES_DISALLOWED = wregex(L"WHERE|and|or|[0-9_].*"); // TODO: more keywords |
52 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 |
53 |
53 |
54 shared_ptr<writer::RelationalWriter> relationalWriter; |
54 shared_ptr<writer::RelationalWriter> relationalWriter; |
55 |
55 |
56 wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
56 wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
57 wchar_t* pythonProgramName; |
57 wchar_t* pythonProgramName; |
126 for (int i = 0; i < currentRecord.size(); i++) { |
126 for (int i = 0; i < currentRecord.size(); i++) { |
127 // TODO: pass particular data-types to Python, not only strings |
127 // TODO: pass particular data-types to Python, not only strings |
128 PyObject* pyValue = PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()); |
128 PyObject* pyValue = PyUnicode_FromString(convertor.to_bytes(currentRecord[i]).c_str()); |
129 PyList_SetItem(pyRecord, i, pyValue); |
129 PyList_SetItem(pyRecord, i, pyValue); |
130 string_t attributeName = currentWriterMetadata[i].attributeName; |
130 string_t attributeName = currentWriterMetadata[i].attributeName; |
131 if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED) && !regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) { |
131 if (regex_match(attributeName, ATTRIBUTE_NAMES_ALLOWED)) { |
|
132 if (regex_match(attributeName, ATTRIBUTE_NAMES_DISALLOWED)) attributeName = L"a_" + attributeName; |
132 PyDict_SetItemString(pyDict, convertor.to_bytes(attributeName).c_str(), pyValue); |
133 PyDict_SetItemString(pyDict, convertor.to_bytes(attributeName).c_str(), pyValue); |
133 } |
134 } |
134 } |
135 } |
135 |
136 |
136 PyDict_SetItemString(pyDict, "r", pyRecord); |
137 PyDict_SetItemString(pyDict, "r", pyRecord); |