parameters: (self, wname, varname, items)
docstring: Generate a function to create Enum-derived class and a cache var.
docstring_summary: Generate a function to create Enum-derived class and a cache var.
docstring_tokens: Generate a function to create Enum - derived class and a cache var .
function: def CreateEnum(self, wname, varname, items):
      """Generate a function to create Enum-derived class and a cache var."""
      yield '// Create Python Enum object (cached in %s) for %s' % (varname,
                                                                    self.cname)
      yield 'static PyObject* %s() {' % wname
      yield I+'PyObject *py_enum_class = nullptr;'
      yield I+'PyObject *modname = nullptr;'
      yield I+'PyObject *py = nullptr;'
      yield I+'PyObject *names = PyTuple_New(%d);' % len(items)
      yield I+'if (names == nullptr) return nullptr;'
      for i, pair in enumerate(items):
        yield I+'if ((py = Py_BuildValue("(NN)", %s, %s)' % pair
        yield I+I+I+') == nullptr) goto err;'
        yield I+'PyTuple_SET_ITEM(names, %d, py);' % i
      yield I+'py = PyUnicode_FromString("%s");' % self.pyname
      yield I+'if (py == nullptr) {'
      yield I+'  goto err;'
      yield I+'}'
      yield I+'modname = PyUnicode_FromString(ThisModuleName);'
      yield I+'if (modname == nullptr) {'
      yield I+'  goto err;'
      yield I+'}'
      yield I+('py_enum_class = PyObject_CallFunctionObjArgs(_%s, py, names, '
               'nullptr);' % self.wrapper_type)
      yield I+'if (py_enum_class != nullptr) {'
      yield I+I+'PyObject_SetAttrString(py_enum_class, "__module__", modname);'
      yield I+'}'
      yield 'err:'
      yield I+'Py_XDECREF(modname);'
      yield I+'Py_XDECREF(py);'
      yield I+'Py_XDECREF(names);'
      yield I+'return py_enum_class;'
      yield '}'
      yield ''
      yield 'static PyObject* %s{};  // set by above func in Init()' % varname
function_tokens: def CreateEnum ( self , wname , varname , items ) : yield '// Create Python Enum object (cached in %s) for %s' % ( varname , self . cname ) yield 'static PyObject* %s() {' % wname yield I + 'PyObject *py_enum_class = nullptr;' yield I + 'PyObject *modname = nullptr;' yield I + 'PyObject *py = nullptr;' yield I + 'PyObject *names = PyTuple_New(%d);' % len ( items ) yield I + 'if (names == nullptr) return nullptr;' for i , pair in enumerate ( items ) : yield I + 'if ((py = Py_BuildValue("(NN)", %s, %s)' % pair yield I + I + I + ') == nullptr) goto err;' yield I + 'PyTuple_SET_ITEM(names, %d, py);' % i yield I + 'py = PyUnicode_FromString("%s");' % self . pyname yield I + 'if (py == nullptr) {' yield I + '  goto err;' yield I + '}' yield I + 'modname = PyUnicode_FromString(ThisModuleName);' yield I + 'if (modname == nullptr) {' yield I + '  goto err;' yield I + '}' yield I + ( 'py_enum_class = PyObject_CallFunctionObjArgs(_%s, py, names, ' 'nullptr);' % self . wrapper_type ) yield I + 'if (py_enum_class != nullptr) {' yield I + I + 'PyObject_SetAttrString(py_enum_class, "__module__", modname);' yield I + '}' yield 'err:' yield I + 'Py_XDECREF(modname);' yield I + 'Py_XDECREF(py);' yield I + 'Py_XDECREF(names);' yield I + 'return py_enum_class;' yield '}' yield '' yield 'static PyObject* %s{};  // set by above func in Init()' % varname