def parse_tuple_code(self):

        declare_return = 'py::object return_val;\n' \
                         'int exception_occurred = 0;\n' \
                         'PyObject *py_local_dict = NULL;\n'
        arg_string_list = self.arg_specs.variable_as_strings() + ['"local_dict"']
        arg_strings = ','.join(arg_string_list)
        if arg_strings:
            arg_strings += ','
        declare_kwlist = 'static const char *kwlist[] = {%s NULL};\n' % \
                         arg_strings

        py_objects = ', '.join(self.arg_specs.py_pointers())
        init_flags = ', '.join(self.arg_specs.init_flags())
        init_flags_init = '= '.join(self.arg_specs.init_flags())
        py_vars = ' = '.join(self.arg_specs.py_variables())
        if py_objects:
            declare_py_objects = 'PyObject ' + py_objects + ';\n'
            declare_py_objects += 'int ' + init_flags + ';\n'
            init_values = py_vars + ' = NULL;\n'
            init_values += init_flags_init + ' = 0;\n\n'
        else:
            declare_py_objects = ''
            init_values = ''

        #Each variable is in charge of its own cleanup now.
        #cnt = len(arg_list)
        #declare_cleanup = "blitz::TinyVector<PyObject*,%d> clean_up(0);\n" % cnt

        ref_string = ', '.join(self.arg_specs.py_references())
        if ref_string:
            ref_string += ', &py_local_dict'
        else:
            ref_string = '&py_local_dict'

        format = "O" * len(self.arg_specs) + "|O" + ':' + self.name
        parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \
                             'kywds,"%s",const_cast<char**>(kwlist),%s))\n' % \
                             (format,ref_string)
        parse_tuple += '   return NULL;\n'

        return declare_return + declare_kwlist + declare_py_objects  \
               + init_values + parse_tuple
Create code block for PyArg_ParseTuple.  Variable declarations
dataset/ETHPy150Open scipy/scipy/scipy/weave/ext_tools.py/ext_function_from_specs.parse_tuple_code