FreeCAD
1560 строк · 49.9 Кб
1#! python
2# -*- coding: utf-8 -*-
3# (c) 2006 Juergen Riegel
4
5
6from . import template
7import os, sys
8import generateBase.generateModel_Module
9import generateBase.generateTools
10
11
12class TemplateClassPyExport(template.ModelTemplate):
13def Generate(self):
14# self.ParentNamespace = "Base"
15# self.Namespace = "Base"
16encoding = sys.getfilesystemencoding()
17path = self.path
18exportName = self.export.Name
19dirname = self.dirname
20
21def escapeString(s, indent=4):
22"""Escapes a string for use as literal in C++ code"""
23s = s.strip() # This allows UserDocu-tags on their own lines without adding whitespace
24s = s.replace("\\", "\\\\")
25s = s.replace('"', '\\"')
26s = s.replace("\n", f'\\n"\n{" "*indent}"')
27return s
28
29print("TemplateClassPyExport", path + exportName)
30# Imp.cpp must not exist, neither in path nor in dirname
31if not os.path.exists(path + exportName + "Imp.cpp"):
32if not os.path.exists(dirname + exportName + "Imp.cpp"):
33file = open(path + exportName + "Imp.cpp", "wb")
34generateBase.generateTools.replace(self.TemplateImplement, locals(), file)
35file.close()
36with open(path + exportName + ".cpp", "wb") as file:
37generateBase.generateTools.replace(self.TemplateModule, locals(), file)
38with open(path + exportName + ".h", "wb") as file:
39generateBase.generateTools.replace(self.TemplateHeader, locals(), file)
40# file.write( generateBase.generateTools.replace(self.Template,locals()))
41
42TemplateHeader = """
43// This file is generated by src/Tools/generateTemplates/templateClassPyExport.py out of the XML file
44// Every change you make here gets lost in the next full rebuild!
45#ifndef @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
46#define @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
47
48#include <@self.export.FatherInclude@>
49#include <@self.export.Include@>
50#include <string>
51
52+ if(self.export.ForwardDeclarations != ""):
53// Forward declarations
54@self.export.ForwardDeclarations@
55-
56
57namespace @self.export.Namespace.replace("::"," { namespace ")@
58{
59
60//===========================================================================
61// @self.export.Name@ - Python wrapper
62//===========================================================================
63
64/** The python export class for @self.export.Twin@
65*/
66class @self.export.Namespace.replace("::","_")@Export @self.export.Name@ : public @self.export.FatherNamespace@::@self.export.Father@
67{
68protected:
69~@self.export.Name@() override;
70
71public:
72static PyTypeObject Type;
73static PyMethodDef Methods[];
74+ if (self.export.NumberProtocol):
75static PyNumberMethods Number[];
76-
77+ if (self.export.Sequence):
78static PySequenceMethods Sequence[];
79static PyMappingMethods Mapping[];
80-
81+ if (self.export.RichCompare):
82static PyObject * richCompare(PyObject *v, PyObject *w, int op);
83-
84+ if (self.export.DescriptorGetter):
85static PyObject* descriptorGetter(PyObject* self, PyObject* obj, PyObject* type);
86-
87+ if (self.export.DescriptorSetter):
88static int descriptorSetter(PyObject* self, PyObject* obj, PyObject* value);
89-
90static PyGetSetDef GetterSetter[];
91PyTypeObject *GetType() override {return &Type;}
92
93public:
94@self.export.Name@(@self.export.TwinPointer@ *pcObject, PyTypeObject *T = &Type);
95static PyObject *PyMake(PyTypeObject *, PyObject *, PyObject *);
96int PyInit(PyObject* args, PyObject*k) override;
97
98+ if (self.export.Initialization):
99int initialization();
100int finalization();
101-
102
103using PointerType = @self.export.TwinPointer@*;
104
105PyObject *_repr() override; // the representation
106std::string representation() const;
107
108/** @name callbacks and implementers for the python object methods */
109//@{
110+ for i in self.export.Methode:
111+ if i.Keyword:
112/// callback for the @i.Name@() method
113static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject *kwd);
114+ if i.Static:
115/// implementer for the @i.Name@() method
116static PyObject* @i.Name@(PyObject *args, PyObject *kwd);
117= elif i.Class:
118/// implementer for the @i.Name@() method
119static PyObject* @i.Name@(PyObject *self, PyObject *args, PyObject *kwd);
120= else:
121/// implementer for the @i.Name@() method
122PyObject* @i.Name@(PyObject *args, PyObject *kwd);
123-
124= elif i.NoArgs:
125/// callback for the @i.Name@() method
126static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args);
127+ if i.Static:
128/// implementer for the @i.Name@() method
129static PyObject* @i.Name@();
130= elif i.Class:
131/// implementer for the @i.Name@() method
132static PyObject* @i.Name@(PyObject *self);
133= else:
134/// implementer for the @i.Name@() method
135PyObject* @i.Name@();
136-
137= else:
138/// callback for the @i.Name@() method
139static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args);
140+ if i.Static:
141/// implementer for the @i.Name@() method
142static PyObject* @i.Name@(PyObject *args);
143= elif i.Class:
144/// implementer for the @i.Name@() method
145static PyObject* @i.Name@(PyObject *self, PyObject *args);
146= else:
147/// implementer for the @i.Name@() method
148PyObject* @i.Name@(PyObject *args);
149-
150-
151-
152//@}
153
154+ if (self.export.NumberProtocol):
155/** @name callbacks and implementers for the python object number protocol */
156//@{
157/// callback for the number_add_handler
158static PyObject * number_add_handler (PyObject *self, PyObject *other);
159/// callback for the number_subtract_handler
160static PyObject * number_subtract_handler (PyObject *self, PyObject *other);
161/// callback for the number_multiply_handler
162static PyObject * number_multiply_handler (PyObject *self, PyObject *other);
163/// callback for the number_divide_handler
164static PyObject * number_divide_handler (PyObject *self, PyObject *other);
165/// callback for the number_remainder_handler
166static PyObject * number_remainder_handler (PyObject *self, PyObject *other);
167/// callback for the number_divmod_handler
168static PyObject * number_divmod_handler (PyObject *self, PyObject *other);
169/// callback for the number_power_handler
170static PyObject * number_power_handler (PyObject *self, PyObject *other, PyObject *modulo);
171/// callback for the number_negative_handler
172static PyObject * number_negative_handler (PyObject *self);
173/// callback for the number_positive_handler
174static PyObject * number_positive_handler (PyObject *self);
175/// callback for the number_absolute_handler
176static PyObject * number_absolute_handler (PyObject *self);
177/// callback for the number_nonzero_handler
178static int number_nonzero_handler (PyObject *self);
179/// callback for the number_invert_handler
180static PyObject * number_invert_handler (PyObject *self);
181/// callback for the number_lshift_handler
182static PyObject * number_lshift_handler (PyObject *self, PyObject *other);
183/// callback for the number_rshift_handler
184static PyObject * number_rshift_handler (PyObject *self, PyObject *other);
185/// callback for the number_and_handler
186static PyObject * number_and_handler (PyObject *self, PyObject *other);
187/// callback for the number_xor_handler
188static PyObject * number_xor_handler (PyObject *self, PyObject *other);
189/// callback for the number_or_handler
190static PyObject * number_or_handler (PyObject *self, PyObject *other);
191/// callback for the number_int_handler
192static PyObject * number_int_handler (PyObject *self);
193/// callback for the number_float_handler
194static PyObject * number_float_handler (PyObject *self);
195//@}
196-
197+ if (self.export.Sequence):
198/** @name callbacks and implementers for the python object sequence protocol */
199//@{
200+ if (self.export.Sequence.sq_length):
201static Py_ssize_t sequence_length(PyObject *);
202-
203+ if (self.export.Sequence.sq_concat):
204static PyObject* sequence_concat(PyObject *, PyObject *);
205-
206+ if (self.export.Sequence.sq_repeat):
207static PyObject * sequence_repeat(PyObject *, Py_ssize_t);
208-
209+ if (self.export.Sequence.sq_item):
210static PyObject * sequence_item(PyObject *, Py_ssize_t);
211-
212+ if (self.export.Sequence.mp_subscript):
213static PyObject * mapping_subscript(PyObject *, PyObject *);
214-
215+ if (self.export.Sequence.sq_ass_item):
216static int sequence_ass_item(PyObject *, Py_ssize_t, PyObject *);
217-
218+ if (self.export.Sequence.mp_ass_subscript):
219static int mapping_ass_subscript(PyObject *, PyObject *, PyObject *);
220-
221+ if (self.export.Sequence.sq_contains):
222static int sequence_contains(PyObject *, PyObject *);
223-
224+ if (self.export.Sequence.sq_inplace_concat):
225static PyObject* sequence_inplace_concat(PyObject *, PyObject *);
226-
227+ if (self.export.Sequence.sq_inplace_repeat):
228static PyObject * sequence_inplace_repeat(PyObject *, Py_ssize_t);
229-
230//@}
231-
232
233/** @name callbacks and implementers for the python object attributes */
234//@{
235+ for i in self.export.Attribute:
236///getter callback for the @i.Name@ attribute
237static PyObject * staticCallback_get@i.Name@ (PyObject *self, void *closure);
238/// getter for the @i.Name@ attribute
239Py::@i.Parameter.Type@ get@i.Name@() const;
240/// setter callback for the @i.Name@ attribute
241static int staticCallback_set@i.Name@ (PyObject *self, PyObject *value, void *closure);
242+ if (i.ReadOnly):
243// no setter method, @i.Name@ is read only!
244= else:
245/// setter for the @i.Name@ attribute
246void set@i.Name@(Py::@i.Parameter.Type@ arg);
247-
248-
249//@}
250
251+ if(self.export.CustomAttributes is not None):
252/// getter method for special attributes (e.g. dynamic ones)
253PyObject *getCustomAttributes(const char* attr) const;
254/// setter for special attributes (e.g. dynamic ones)
255/// Output: Success=1, Failure=-1, Ignore=0
256int setCustomAttributes(const char* attr, PyObject *obj);
257PyObject *_getattr(const char *attr) override; // __getattr__ function
258int _setattr(const char *attr, PyObject *value) override; // __setattr__ function
259-
260
261/// getter for the object handled by this class
262@self.export.TwinPointer@ *get@self.export.Twin@Ptr() const;
263
264+ if(self.export.ClassDeclarations != ""):
265/** @name additional declarations and methods for the wrapper class */
266//@{
267@self.export.ClassDeclarations@
268//@}
269-
270};
271
272@"}"*len(self.export.Namespace.split("::"))@ //namespace @self.export.Namespace@
273
274#endif // @self.export.Namespace.upper().replace("::", "_")@_@self.export.Name.upper()@_H
275
276"""
277
278TemplateModule = """
279// This file is generated by src/Tools/generateTemplates/templateClassPyExport.py out of the .XML file
280// Every change you make here gets lost in the next full rebuild!
281// This File is normally built as an include in @self.export.Name@Imp.cpp! It's not intended to be in a project!
282
283#include <boost/filesystem/path.hpp>
284#include <boost/filesystem/operations.hpp>
285#include <boost/filesystem/exception.hpp>
286#include <Base/PyObjectBase.h>
287#include <Base/Console.h>
288#include <Base/Exception.h>
289#include <CXX/Objects.hxx>
290
291#if defined(__clang__)
292# pragma clang diagnostic push
293# pragma clang diagnostic ignored "-Wdeprecated-declarations"
294#endif
295
296using Base::streq;
297using namespace @self.export.Namespace@;
298
299/// Type structure of @self.export.Name@
300PyTypeObject @self.export.Name@::Type = {
301PyVarObject_HEAD_INIT(&PyType_Type,0)
302+ if (self.export.PythonName):
303"@self.export.PythonName@", /*tp_name*/
304= else:
305"@self.export.Namespace@.@self.export.Twin@", /*tp_name*/
306-
307sizeof(@self.export.Name@), /*tp_basicsize*/
3080, /*tp_itemsize*/
309/* methods */
310PyDestructor, /*tp_dealloc*/
311#if PY_VERSION_HEX >= 0x03080000
3120, /*tp_vectorcall_offset*/
313#else
314nullptr, /*tp_print*/
315#endif
316nullptr, /*tp_getattr*/
317nullptr, /*tp_setattr*/
318nullptr, /*tp_compare*/
319__repr, /*tp_repr*/
320+ if (self.export.NumberProtocol):
321@self.export.Namespace@::@self.export.Name@::Number, /*tp_as_number*/
322= else:
323nullptr, /*tp_as_number*/
324-
325+ if (self.export.Sequence):
326@self.export.Namespace@::@self.export.Name@::Sequence, /*tp_as_sequence*/
327@self.export.Namespace@::@self.export.Name@::Mapping, /*tp_as_mapping*/
328= else:
329nullptr, /*tp_as_sequence*/
330nullptr, /*tp_as_mapping*/
331-
332nullptr, /*tp_hash*/
333nullptr, /*tp_call */
334nullptr, /*tp_str */
335__getattro, /*tp_getattro*/
336__setattro, /*tp_setattro*/
337/* --- Functions to access object as input/output buffer ---------*/
338nullptr, /* tp_as_buffer */
339/* --- Flags to define presence of optional/expanded features */
340Py_TPFLAGS_BASETYPE|Py_TPFLAGS_DEFAULT, /*tp_flags */
341"@escapeString(self.export.Documentation.UserDocu, indent=4)@", /*tp_doc */
342nullptr, /*tp_traverse */
343nullptr, /*tp_clear */
344+ if (self.export.RichCompare):
345@self.export.Namespace@::@self.export.Name@::richCompare, /*tp_richcompare*/
346= else:
347nullptr, /*tp_richcompare */
348-
3490, /*tp_weaklistoffset */
350nullptr, /*tp_iter */
351nullptr, /*tp_iternext */
352@self.export.Namespace@::@self.export.Name@::Methods, /*tp_methods */
353nullptr, /*tp_members */
354@self.export.Namespace@::@self.export.Name@::GetterSetter, /*tp_getset */
355&@self.export.FatherNamespace@::@self.export.Father@::Type, /*tp_base */
356nullptr, /*tp_dict */
357+ if (self.export.DescriptorGetter):
358@self.export.Namespace@::@self.export.Name@::descriptorGetter, /*tp_descr_get */
359= else:
360nullptr, /*tp_descr_get */
361-
362+ if (self.export.DescriptorSetter):
363@self.export.Namespace@::@self.export.Name@::descriptorSetter, /*tp_descr_set */
364= else:
365nullptr, /*tp_descr_set */
366-
3670, /*tp_dictoffset */
368__PyInit, /*tp_init */
369nullptr, /*tp_alloc */
370@self.export.Namespace@::@self.export.Name@::PyMake,/*tp_new */
371nullptr, /*tp_free Low-level free-memory routine */
372nullptr, /*tp_is_gc For PyObject_IS_GC */
373nullptr, /*tp_bases */
374nullptr, /*tp_mro method resolution order */
375nullptr, /*tp_cache */
376nullptr, /*tp_subclasses */
377nullptr, /*tp_weaklist */
378nullptr, /*tp_del */
3790, /*tp_version_tag */
380nullptr /*tp_finalize */
381#if PY_VERSION_HEX >= 0x03090000
382,nullptr /*tp_vectorcall */
383#if PY_VERSION_HEX >= 0x030c0000
384,0 /*tp_watched */
385#endif
386#elif PY_VERSION_HEX >= 0x03080000
387,nullptr /*tp_vectorcall */
388/* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
389,nullptr /*tp_print */
390#endif
391};
392
393/// Methods structure of @self.export.Name@
394PyMethodDef @self.export.Name@::Methods[] = {
395+ for i in self.export.Methode:
396{"@i.Name@",
397+ if i.Keyword:
398+ if i.Class:
399reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
400METH_VARARGS|METH_KEYWORDS|METH_CLASS,
401= elif i.Static:
402reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
403METH_VARARGS|METH_KEYWORDS|METH_STATIC,
404= else:
405reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
406METH_VARARGS|METH_KEYWORDS,
407-
408= elif i.NoArgs:
409+ if i.Class:
410reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
411METH_NOARGS|METH_CLASS,
412= elif i.Static:
413reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
414METH_NOARGS|METH_STATIC,
415= else:
416reinterpret_cast<PyCFunction>( staticCallback_@i.Name@ ),
417METH_NOARGS,
418-
419= elif i.Class:
420reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
421METH_VARARGS|METH_CLASS,
422= elif i.Static:
423reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) ()>( staticCallback_@i.Name@ )),
424METH_VARARGS|METH_STATIC,
425= else:
426reinterpret_cast<PyCFunction>( staticCallback_@i.Name@ ),
427METH_VARARGS,
428-
429"@escapeString(i.Documentation.UserDocu, indent=8)@"
430},
431-
432{nullptr, nullptr, 0, nullptr} /* Sentinel */
433};
434
435+ if (self.export.NumberProtocol):
436PyNumberMethods @self.export.Name@::Number[] = { {
437number_add_handler,
438number_subtract_handler,
439number_multiply_handler,
440number_remainder_handler,
441number_divmod_handler,
442number_power_handler,
443number_negative_handler,
444number_positive_handler,
445number_absolute_handler,
446number_nonzero_handler,
447number_invert_handler,
448number_lshift_handler,
449number_rshift_handler,
450number_and_handler,
451number_xor_handler,
452number_or_handler,
453number_int_handler,
454nullptr,
455number_float_handler,
456nullptr, /*nb_inplace_add*/
457nullptr, /*nb_inplace_subtract*/
458nullptr, /*nb_inplace_multiply*/
459nullptr, /*nb_inplace_remainder*/
460nullptr, /*nb_inplace_power*/
461nullptr, /*nb_inplace_lshift*/
462nullptr, /*nb_inplace_rshift*/
463nullptr, /*nb_inplace_and*/
464nullptr, /*nb_inplace_xor*/
465nullptr, /*nb_inplace_or*/
466nullptr, /*nb_floor_divide*/
467number_divide_handler, /*nb_true_divide*/
468nullptr, /*nb_inplace_floor_divide*/
469nullptr, /*nb_inplace_true_divide*/
470nullptr /*nb_index*/
471,nullptr /*nb_matrix_multiply*/
472,nullptr /*nb_inplace_matrix_multiply*/
473} };
474-
475
476+ if (self.export.Sequence):
477PySequenceMethods @self.export.Name@::Sequence[] = { {
478+ if (self.export.Sequence.sq_length):
479sequence_length,
480= else:
481nullptr,
482-
483+ if (self.export.Sequence.sq_concat):
484sequence_concat,
485= else:
486nullptr,
487-
488+ if (self.export.Sequence.sq_repeat):
489sequence_repeat,
490= else:
491nullptr,
492-
493+ if (self.export.Sequence.sq_item):
494sequence_item,
495= else:
496nullptr,
497-
498nullptr,
499+ if (self.export.Sequence.sq_ass_item):
500sequence_ass_item,
501= else:
502nullptr,
503-
504nullptr,
505+ if (self.export.Sequence.sq_contains):
506sequence_contains,
507= else:
508nullptr,
509-
510+ if (self.export.Sequence.sq_inplace_concat):
511sequence_inplace_concat,
512= else:
513nullptr,
514-
515+ if (self.export.Sequence.sq_inplace_repeat):
516sequence_inplace_repeat,
517= else:
518nullptr
519-
520} };
521
522PyMappingMethods @self.export.Name@::Mapping[] = { {
523+ if (self.export.Sequence.sq_length):
524sequence_length,
525= else:
526nullptr,
527-
528+ if (self.export.Sequence.mp_subscript):
529mapping_subscript,
530= else:
531nullptr,
532-
533+ if (self.export.Sequence.mp_ass_subscript):
534mapping_ass_subscript,
535= else:
536nullptr,
537-
538} };
539-
540
541/// Attribute structure of @self.export.Name@
542PyGetSetDef @self.export.Name@::GetterSetter[] = {
543+ for i in self.export.Attribute:
544{"@i.Name@",
545(getter) staticCallback_get@i.Name@,
546(setter) staticCallback_set@i.Name@,
547"@escapeString(i.Documentation.UserDocu, indent=8)@",
548nullptr
549},
550-
551{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
552};
553
554+ for i in self.export.Methode:
555// @i.Name@() callback and implementer
556// PyObject* @self.export.Name@::@i.Name@(PyObject *args){};
557// has to be implemented in @self.export.Name@Imp.cpp
558+ if i.Keyword:
559PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject * kwd)
560= elif i.NoArgs:
561PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject * Py_UNUSED(args))
562= else:
563PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject *args)
564-
565{
566+ if not i.Static and not i.Class:
567// make sure that not a null pointer is passed
568if (!self) {
569PyErr_SetString(PyExc_TypeError, "descriptor '@i.Name@' of '@self.export.Namespace@.@self.export.Twin@' object needs an argument");
570return nullptr;
571}
572
573// test if twin object isn't already deleted
574if (!static_cast<PyObjectBase*>(self)->isValid()) {
575PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
576return nullptr;
577}
578
579+ if (not i.Const):
580// test if object is set Const
581if (static_cast<PyObjectBase*>(self)->isConst()) {
582PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
583return nullptr;
584}
585-
586
587-
588try { // catches all exceptions coming up from c++ and generate a python exception
589+ if i.Keyword:
590+ if i.Static:
591(void)self;
592PyObject* ret = @self.export.Name@::@i.Name@(args, kwd);
593= elif i.Class:
594PyObject* ret = @self.export.Name@::@i.Name@(self, args, kwd);
595= else:
596PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@(args, kwd);
597-
598= elif i.NoArgs:
599+ if i.Static:
600(void)self;
601PyObject* ret = @self.export.Name@::@i.Name@();
602= elif i.Class:
603PyObject* ret = @self.export.Name@::@i.Name@(self);
604= else:
605PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@();
606-
607= else:
608+ if i.Static:
609(void)self;
610PyObject* ret = @self.export.Name@::@i.Name@(args);
611= elif i.Class:
612PyObject* ret = @self.export.Name@::@i.Name@(self, args);
613= else:
614PyObject* ret = static_cast<@self.export.Name@*>(self)->@i.Name@(args);
615-
616-
617+ if not i.Static and not i.Class:
618+ if (not i.Const):
619if (ret != nullptr)
620static_cast<@self.export.Name@*>(self)->startNotify();
621-
622-
623return ret;
624} // Please sync the following catch implementation with PY_CATCH
625catch(Base::Exception &e)
626{
627auto pye = e.getPyExceptionType();
628if(!pye)
629pye = Base::PyExc_FC_GeneralError;
630PyErr_SetObject(pye, e.getPyObject());
631return nullptr;
632}
633catch(const std::exception &e)
634{
635PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
636return nullptr;
637}
638catch(const Py::Exception&)
639{
640// The exception text is already set
641return nullptr;
642}
643#ifndef DONT_CATCH_CXX_EXCEPTIONS
644catch(...)
645{
646PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown C++ exception");
647return nullptr;
648}
649#endif
650}
651
652-
653+ for i in self.export.Attribute:
654// @i.Name@() callback and implementer
655// PyObject* @self.export.Name@::@i.Name@(PyObject *args){};
656// has to be implemented in @self.export.Name@Imp.cpp
657PyObject * @self.export.Name@::staticCallback_get@i.Name@ (PyObject *self, void * /*closure*/)
658{
659if (!static_cast<PyObjectBase*>(self)->isValid()){
660PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
661return nullptr;
662}
663
664try {
665return Py::new_reference_to(static_cast<@self.export.Name@*>(self)->get@i.Name@());
666} catch (const Py::Exception&) {
667// The exception text is already set
668return nullptr;
669} catch (...) {
670PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown exception while reading attribute '@i.Name@' of object '@self.export.Twin@'");
671return nullptr;
672}
673}
674
675+ if (i.ReadOnly):
676int @self.export.Name@::staticCallback_set@i.Name@ (PyObject *self, PyObject * /*value*/, void * /*closure*/)
677{
678if (!static_cast<PyObjectBase*>(self)->isValid()){
679PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
680return -1;
681}
682
683PyErr_SetString(PyExc_AttributeError, "Attribute '@i.Name@' of object '@self.export.Twin@' is read-only");
684return -1;
685}
686= else:
687int @self.export.Name@::staticCallback_set@i.Name@ (PyObject *self, PyObject *value, void * /*closure*/)
688{
689if (!static_cast<PyObjectBase*>(self)->isValid()){
690PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
691return -1;
692}
693if (static_cast<PyObjectBase*>(self)->isConst()){
694PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
695return -1;
696}
697
698try {
699+ if (i.Parameter.Type == "Float"):
700static_cast<@self.export.Name@*>(self)->set@i.Name@(Py::@i.Parameter.Type@(PyNumber_Float(value),true));
701= else:
702static_cast<@self.export.Name@*>(self)->set@i.Name@(Py::@i.Parameter.Type@(value,false));
703-
704return 0;
705} catch (const Py::Exception&) {
706// The exception text is already set
707return -1;
708} catch (...) {
709PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown exception while writing attribute '@i.Name@' of object '@self.export.Twin@'");
710return -1;
711}
712}
713-
714
715-
716
717
718
719//--------------------------------------------------------------------------
720// Constructor
721//--------------------------------------------------------------------------
722@self.export.Name@::@self.export.Name@(@self.export.TwinPointer@ *pcObject, PyTypeObject *T)
723: @self.export.Father@(static_cast<@self.export.Father@::PointerType>(pcObject), T)
724{
725+ if (self.export.Reference):
726pcObject->ref();
727-
728+ if (self.export.Initialization):
729initialization();
730-
731+ if (self.export.DisableNotify):
732this->setShouldNotify(false);
733-
734}
735
736+ if not (self.export.Constructor):
737PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
738{
739// never create such objects with the constructor
740PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of '@self.export.Name@'.");
741
742return nullptr;
743}
744
745int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
746{
747return 0;
748}
749-
750
751//--------------------------------------------------------------------------
752// destructor
753//--------------------------------------------------------------------------
754@self.export.Name@::~@self.export.Name@() // Everything handled in parent
755{
756+ if (self.export.Reference):
757get@self.export.Twin@Ptr()->unref();
758-
759+ if (self.export.Delete):
760// delete the handled object when the PyObject dies
761@self.export.Name@::PointerType ptr = static_cast<@self.export.Name@::PointerType>(_pcTwinPointer);
762delete ptr;
763-
764+ if (self.export.Initialization):
765finalization();
766-
767}
768
769//--------------------------------------------------------------------------
770// @self.export.Name@ representation
771//--------------------------------------------------------------------------
772PyObject *@self.export.Name@::_repr()
773{
774return Py_BuildValue("s", representation().c_str());
775}
776
777+ if(self.export.CustomAttributes is not None):
778//--------------------------------------------------------------------------
779// @self.export.Name@ Attributes
780//--------------------------------------------------------------------------
781PyObject *@self.export.Name@::_getattr(const char *attr) // __getattr__ function: note only need to handle new state
782{
783try {
784// getter method for special Attributes (e.g. dynamic ones)
785PyObject *r = getCustomAttributes(attr);
786if(r) return r;
787} // Please sync the following catch implementation with PY_CATCH
788catch(Base::Exception &e)
789{
790auto pye = e.getPyExceptionType();
791if(!pye)
792pye = Base::PyExc_FC_GeneralError;
793PyErr_SetObject(pye, e.getPyObject());
794return nullptr;
795}
796catch(const std::exception &e)
797{
798PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
799return nullptr;
800}
801catch(const Py::Exception&)
802{
803// The exception text is already set
804return nullptr;
805}
806#ifndef DONT_CATCH_CXX_EXCEPTIONS
807catch(...)
808{
809PyErr_SetString(Base::PyExc_FC_GeneralError,"Unknown C++ exception");
810return nullptr;
811}
812#endif
813
814PyMethodDef *ml = Methods;
815for (; ml->ml_name != nullptr; ml++) {
816if (attr[0] == ml->ml_name[0] &&
817strcmp(attr+1, ml->ml_name+1) == 0)
818return PyCFunction_New(ml, this);
819}
820
821PyErr_Clear();
822return @self.export.Father@::_getattr(attr);
823}
824
825int @self.export.Name@::_setattr(const char *attr, PyObject *value) // __setattr__ function: note only need to handle new state
826{
827try {
828// setter for special Attributes (e.g. dynamic ones)
829int r = setCustomAttributes(attr, value);
830// r = 1: handled
831// r = -1: error
832// r = 0: ignore
833if (r == 1)
834return 0;
835else if (r == -1)
836return -1;
837} // Please sync the following catch implementation with PY_CATCH
838catch(Base::Exception &e)
839{
840auto pye = e.getPyExceptionType();
841if(!pye)
842pye = Base::PyExc_FC_GeneralError;
843PyErr_SetObject(pye, e.getPyObject());
844return -1;
845}
846catch(const std::exception &e)
847{
848PyErr_SetString(Base::PyExc_FC_GeneralError, e.what());
849return -1;
850}
851catch(const Py::Exception&)
852{
853// The exception text is already set
854return -1;
855}
856#ifndef DONT_CATCH_CXX_EXCEPTIONS
857catch(...)
858{
859PyErr_SetString(Base::PyExc_FC_GeneralError, "Unknown C++ exception");
860return -1;
861}
862#endif
863
864return @self.export.Father@::_setattr(attr, value);
865}
866-
867
868@self.export.TwinPointer@ *@self.export.Name@::get@self.export.Twin@Ptr() const
869{
870return static_cast<@self.export.TwinPointer@ *>(_pcTwinPointer);
871}
872
873#if defined(__clang__)
874# pragma clang diagnostic pop
875#endif
876
877#if 0
878/* From here on come the methods you have to implement, but NOT in this module. Implement in @self.export.Name@Imp.cpp! This prototypes
879* are just for convenience when you add a new method.
880*/
881
882+ if (self.export.Constructor):
883PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
884{
885// create a new instance of @self.export.Name@ and the Twin object
886return new @self.export.Name@(new @self.export.TwinPointer@);
887}
888
889// constructor method
890int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
891{
892return 0;
893}
894-
895
896+ if (self.export.Initialization):
897int @self.export.Name@::initialization()
898{
899return 0;
900}
901int @self.export.Name@::finalization()
902{
903return 0;
904}
905-
906
907// returns a string which represents the object e.g. when printed in python
908std::string @self.export.Name@::representation() const
909{
910return {"<@self.export.Twin@ object>"};
911}
912+ for i in self.export.Methode:
913
914+ if i.Keyword:
915+ if i.Class:
916PyObject* @self.export.Name@::@i.Name@(PyObject *self, PyObject *args, PyObject *kwds)
917= else:
918PyObject* @self.export.Name@::@i.Name@(PyObject *args, PyObject *kwds)
919-
920= elif i.NoArgs:
921+ if i.Class:
922PyObject* @self.export.Name@::@i.Name@(PyObject *self)
923= else:
924PyObject* @self.export.Name@::@i.Name@()
925-
926= else:
927+ if i.Class:
928PyObject* @self.export.Name@::@i.Name@(PyObject *self, PyObject *args)
929= else:
930PyObject* @self.export.Name@::@i.Name@(PyObject *args)
931-
932-
933{
934PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
935return nullptr;
936}
937-
938
939+ if (self.export.NumberProtocol):
940PyObject* @self.export.Name@::number_add_handler(PyObject* /*self*/, PyObject* /*other*/)
941{
942PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
943return nullptr;
944}
945
946PyObject* @self.export.Name@::number_subtract_handler(PyObject* /*self*/, PyObject* /*other*/)
947{
948PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
949return nullptr;
950}
951
952PyObject* @self.export.Name@::number_multiply_handler(PyObject* /*self*/, PyObject* /*other*/)
953{
954PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
955return nullptr;
956}
957
958PyObject * @self.export.Name@::number_divide_handler (PyObject* /*self*/, PyObject* /*other*/)
959{
960PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
961return nullptr;
962}
963
964PyObject * @self.export.Name@::number_remainder_handler (PyObject* /*self*/, PyObject* /*other*/)
965{
966PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
967return nullptr;
968}
969
970PyObject * @self.export.Name@::number_divmod_handler (PyObject* /*self*/, PyObject* /*other*/)
971{
972PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
973return nullptr;
974}
975
976PyObject * @self.export.Name@::number_power_handler (PyObject* /*self*/, PyObject* /*other*/, PyObject* /*modulo*/)
977{
978PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
979return nullptr;
980}
981
982PyObject * @self.export.Name@::number_negative_handler (PyObject* /*self*/)
983{
984PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
985return nullptr;
986}
987
988PyObject * @self.export.Name@::number_positive_handler (PyObject* /*self*/)
989{
990PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
991return nullptr;
992}
993
994PyObject * @self.export.Name@::number_absolute_handler (PyObject* /*self*/)
995{
996PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
997return nullptr;
998}
999
1000int @self.export.Name@::number_nonzero_handler (PyObject* /*self*/)
1001{
1002return 1;
1003}
1004
1005PyObject * @self.export.Name@::number_invert_handler (PyObject* /*self*/)
1006{
1007PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1008return nullptr;
1009}
1010
1011PyObject * @self.export.Name@::number_lshift_handler (PyObject* /*self*/, PyObject* /*other*/)
1012{
1013PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1014return nullptr;
1015}
1016
1017PyObject * @self.export.Name@::number_rshift_handler (PyObject* /*self*/, PyObject* /*other*/)
1018{
1019PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1020return nullptr;
1021}
1022
1023PyObject * @self.export.Name@::number_and_handler (PyObject* /*self*/, PyObject* /*other*/)
1024{
1025PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1026return nullptr;
1027}
1028
1029PyObject * @self.export.Name@::number_xor_handler (PyObject* /*self*/, PyObject* /*other*/)
1030{
1031PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1032return nullptr;
1033}
1034
1035PyObject * @self.export.Name@::number_or_handler (PyObject* /*self*/, PyObject* /*other*/)
1036{
1037PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1038return nullptr;
1039}
1040
1041int @self.export.Name@::number_coerce_handler (PyObject** /*self*/, PyObject** /*other*/)
1042{
1043return 1;
1044}
1045
1046PyObject * @self.export.Name@::number_int_handler (PyObject* /*self*/)
1047{
1048PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1049return nullptr;
1050}
1051
1052PyObject * @self.export.Name@::number_long_handler (PyObject* /*self*/)
1053{
1054PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1055return nullptr;
1056}
1057
1058PyObject * @self.export.Name@::number_float_handler (PyObject* /*self*/)
1059{
1060PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1061return nullptr;
1062}
1063
1064PyObject * @self.export.Name@::number_oct_handler (PyObject* /*self*/)
1065{
1066PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1067return nullptr;
1068}
1069
1070PyObject * @self.export.Name@::number_hex_handler (PyObject* /*self*/)
1071{
1072PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1073return nullptr;
1074}
1075-
1076+ if (self.export.Sequence):
1077+ if (self.export.Sequence.sq_length):
1078
1079Py_ssize_t @self.export.Name@::sequence_length(PyObject *)
1080{
1081PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1082return -1;
1083}
1084-
1085+ if (self.export.Sequence.sq_concat):
1086
1087PyObject* @self.export.Name@::sequence_concat(PyObject *, PyObject *)
1088{
1089PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1090return nullptr;
1091}
1092-
1093+ if (self.export.Sequence.sq_repeat):
1094
1095PyObject * @self.export.Name@::sequence_repeat(PyObject *, Py_ssize_t)
1096{
1097PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1098return nullptr;
1099}
1100-
1101+ if (self.export.Sequence.sq_item):
1102
1103PyObject * @self.export.Name@::sequence_item(PyObject *, Py_ssize_t)
1104{
1105PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1106return nullptr;
1107}
1108-
1109+ if (self.export.Sequence.mp_subscript):
1110
1111PyObject * @self.export.Name@::mapping_subscript(PyObject *, PyObject *)
1112{
1113PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1114return nullptr;
1115}
1116-
1117+ if (self.export.Sequence.sq_ass_item):
1118
1119int @self.export.Name@::sequence_ass_item(PyObject *, Py_ssize_t, PyObject *)
1120{
1121PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1122return -1;
1123}
1124-
1125+ if (self.export.Sequence.mp_ass_subscript):
1126
1127int @self.export.Name@::mapping_ass_subscript(PyObject *, PyObject *, PyObject *)
1128{
1129PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1130return -1;
1131}
1132-
1133+ if (self.export.Sequence.sq_contains):
1134
1135int @self.export.Name@::sequence_contains(PyObject *, PyObject *)
1136{
1137PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1138return -1;
1139}
1140-
1141+ if (self.export.Sequence.sq_inplace_concat):
1142
1143PyObject* @self.export.Name@::sequence_inplace_concat(PyObject *, PyObject *)
1144{
1145PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1146return nullptr;
1147}
1148-
1149+ if (self.export.Sequence.sq_inplace_repeat):
1150
1151PyObject * @self.export.Name@::sequence_inplace_repeat(PyObject *, Py_ssize_t)
1152{
1153PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1154return nullptr;
1155}
1156-
1157-
1158
1159+ if (self.export.RichCompare):
1160PyObject* @self.export.Name@::richCompare(PyObject *v, PyObject *w, int op)
1161{
1162PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1163return nullptr;
1164}
1165-
1166+ for i in self.export.Attribute:
1167
1168Py::@i.Parameter.Type@ @self.export.Name@::get@i.Name@() const
1169{
1170//return Py::@i.Parameter.Type@();
1171throw Py::AttributeError("Not yet implemented");
1172}
1173+ if (i.ReadOnly):
1174= else:
1175
1176void @self.export.Name@::set@i.Name@(Py::@i.Parameter.Type@ arg)
1177{
1178throw Py::AttributeError("Not yet implemented");
1179}
1180-
1181-
1182+ if(self.export.CustomAttributes is not None):
1183
1184PyObject *@self.export.Name@::getCustomAttributes(const char* /*attr*/) const
1185{
1186return nullptr;
1187}
1188
1189int @self.export.Name@::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
1190{
1191return 0;
1192}
1193-
1194
1195+ if (self.export.DescriptorGetter):
1196PyObject* @self.export.Name@::descriptorGetter(PyObject* self, PyObject* obj, PyObject* type)
1197{
1198PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1199return nullptr;
1200}
1201-
1202
1203+ if (self.export.DescriptorSetter):
1204int @self.export.Name@::descriptorSetter(PyObject* self, PyObject* obj, PyObject* value)
1205{
1206PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1207return -1;
1208}
1209-
1210#endif
1211
1212
1213"""
1214
1215# Here's the template for the user part of the implementation. This does NOT get overridden if it already exists.
1216TemplateImplement = """
1217#include "PreCompiled.h"
1218
1219#include "@self.export.Include@"
1220
1221// inclusion of the generated files (generated out of @self.export.Name@.xml)
1222#include "@self.export.Name@.h"
1223#include "@self.export.Name@.cpp"
1224
1225using namespace @self.export.Namespace@;
1226
1227// returns a string which represents the object e.g. when printed in python
1228std::string @self.export.Name@::representation() const
1229{
1230return {"<@self.export.Twin@ object>"};
1231}
1232
1233+ if (self.export.Constructor):
1234PyObject *@self.export.Name@::PyMake(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
1235{
1236// create a new instance of @self.export.Name@ and the Twin object
1237return new @self.export.Name@(new @self.export.TwinPointer@);
1238}
1239
1240// constructor method
1241int @self.export.Name@::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
1242{
1243return 0;
1244}
1245-
1246+ if (self.export.Initialization):
1247int @self.export.Name@::initialization()
1248{
1249PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1250return 0;
1251}
1252int @self.export.Name@::finalization()
1253{
1254PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1255return 0;
1256}
1257-
1258
1259+ for i in self.export.Methode:
1260
1261+ if i.Keyword:
1262+ if i.Class:
1263PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/, PyObject * /*args*/, PyObject * /*kwds*/)
1264= else:
1265PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/, PyObject * /*kwds*/)
1266-
1267= elif i.NoArgs:
1268+ if i.Class:
1269PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/)
1270= else:
1271PyObject* @self.export.Name@::@i.Name@()
1272-
1273= else:
1274+ if i.Class:
1275PyObject* @self.export.Name@::@i.Name@(PyObject * /*self*/, PyObject * /*args*/)
1276= else:
1277PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/)
1278-
1279-
1280{
1281PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1282return nullptr;
1283}
1284-
1285
1286+ if (self.export.NumberProtocol):
1287PyObject* @self.export.Name@::number_add_handler(PyObject *self, PyObject *other)
1288{
1289PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1290return nullptr;
1291}
1292
1293PyObject* @self.export.Name@::number_subtract_handler(PyObject *self, PyObject *other)
1294{
1295PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1296return nullptr;
1297}
1298
1299PyObject* @self.export.Name@::number_multiply_handler(PyObject *self, PyObject *other)
1300{
1301PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1302return nullptr;
1303}
1304
1305PyObject * @self.export.Name@::number_divide_handler (PyObject *self, PyObject *other)
1306{
1307PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1308return nullptr;
1309}
1310
1311PyObject * @self.export.Name@::number_remainder_handler (PyObject *self, PyObject *other)
1312{
1313PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1314return nullptr;
1315}
1316
1317PyObject * @self.export.Name@::number_divmod_handler (PyObject *self, PyObject *other)
1318{
1319PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1320return nullptr;
1321}
1322
1323PyObject * @self.export.Name@::number_power_handler (PyObject *self, PyObject *other, PyObject *modulo)
1324{
1325PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1326return nullptr;
1327}
1328
1329PyObject * @self.export.Name@::number_negative_handler (PyObject *self)
1330{
1331PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1332return nullptr;
1333}
1334
1335PyObject * @self.export.Name@::number_positive_handler (PyObject *self)
1336{
1337PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1338return nullptr;
1339}
1340
1341PyObject * @self.export.Name@::number_absolute_handler (PyObject *self)
1342{
1343PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1344return nullptr;
1345}
1346
1347int @self.export.Name@::number_nonzero_handler (PyObject *self)
1348{
1349return 1;
1350}
1351
1352PyObject * @self.export.Name@::number_invert_handler (PyObject *self)
1353{
1354PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1355return nullptr;
1356}
1357
1358PyObject * @self.export.Name@::number_lshift_handler (PyObject *self, PyObject *other)
1359{
1360PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1361return nullptr;
1362}
1363
1364PyObject * @self.export.Name@::number_rshift_handler (PyObject *self, PyObject *other)
1365{
1366PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1367return nullptr;
1368}
1369
1370PyObject * @self.export.Name@::number_and_handler (PyObject *self, PyObject *other)
1371{
1372PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1373return nullptr;
1374}
1375
1376PyObject * @self.export.Name@::number_xor_handler (PyObject *self, PyObject *other)
1377{
1378PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1379return nullptr;
1380}
1381
1382PyObject * @self.export.Name@::number_or_handler (PyObject *self, PyObject *other)
1383{
1384PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1385return nullptr;
1386}
1387
1388int @self.export.Name@::number_coerce_handler (PyObject **self, PyObject **other)
1389{
1390return 1;
1391}
1392
1393PyObject * @self.export.Name@::number_int_handler (PyObject *self)
1394{
1395PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1396return nullptr;
1397}
1398
1399PyObject * @self.export.Name@::number_long_handler (PyObject *self)
1400{
1401PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1402return nullptr;
1403}
1404
1405PyObject * @self.export.Name@::number_float_handler (PyObject *self)
1406{
1407PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1408return nullptr;
1409}
1410
1411PyObject * @self.export.Name@::number_oct_handler (PyObject *self)
1412{
1413PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1414return nullptr;
1415}
1416
1417PyObject * @self.export.Name@::number_hex_handler (PyObject *self)
1418{
1419PyErr_SetString(PyExc_NotImplementedError, "Not implemented");
1420return nullptr;
1421}
1422-
1423
1424+ if (self.export.Sequence):
1425+ if (self.export.Sequence.sq_length):
1426
1427Py_ssize_t @self.export.Name@::sequence_length(PyObject *)
1428{
1429PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1430return -1;
1431}
1432-
1433+ if (self.export.Sequence.sq_concat):
1434
1435PyObject* @self.export.Name@::sequence_concat(PyObject *, PyObject *)
1436{
1437PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1438return nullptr;
1439}
1440-
1441+ if (self.export.Sequence.sq_repeat):
1442
1443PyObject * @self.export.Name@::sequence_repeat(PyObject *, Py_ssize_t)
1444{
1445PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1446return nullptr;
1447}
1448-
1449+ if (self.export.Sequence.sq_item):
1450
1451PyObject * @self.export.Name@::sequence_item(PyObject *, Py_ssize_t)
1452{
1453PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1454return nullptr;
1455}
1456-
1457+ if (self.export.Sequence.mp_subscript):
1458
1459PyObject * @self.export.Name@::mapping_subscript(PyObject *, PyObject *)
1460{
1461PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1462return nullptr;
1463}
1464-
1465+ if (self.export.Sequence.sq_ass_item):
1466
1467int @self.export.Name@::sequence_ass_item(PyObject *, Py_ssize_t, PyObject *)
1468{
1469PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1470return -1;
1471}
1472-
1473+ if (self.export.Sequence.mp_ass_subscript):
1474
1475int @self.export.Name@::mapping_ass_subscript(PyObject *, PyObject *, PyObject *)
1476{
1477PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1478return -1;
1479}
1480-
1481+ if (self.export.Sequence.sq_contains):
1482
1483int @self.export.Name@::sequence_contains(PyObject *, PyObject *)
1484{
1485PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1486return -1;
1487}
1488-
1489+ if (self.export.Sequence.sq_inplace_concat):
1490
1491PyObject* @self.export.Name@::sequence_inplace_concat(PyObject *, PyObject *)
1492{
1493PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1494return nullptr;
1495}
1496-
1497+ if (self.export.Sequence.sq_inplace_repeat):
1498
1499PyObject * @self.export.Name@::sequence_inplace_repeat(PyObject *, Py_ssize_t)
1500{
1501PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1502return nullptr;
1503}
1504-
1505-
1506
1507+ if (self.export.RichCompare):
1508PyObject* @self.export.Name@::richCompare(PyObject *v, PyObject *w, int op)
1509{
1510PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1511return nullptr;
1512}
1513-
1514
1515+ for i in self.export.Attribute:
1516
1517Py::@i.Parameter.Type@ @self.export.Name@::get@i.Name@() const
1518{
1519//return Py::@i.Parameter.Type@();
1520throw Py::AttributeError("Not yet implemented");
1521}
1522+ if (i.ReadOnly):
1523= else:
1524
1525void @self.export.Name@::set@i.Name@(Py::@i.Parameter.Type@ /*arg*/)
1526{
1527throw Py::AttributeError("Not yet implemented");
1528}
1529-
1530-
1531+ if(self.export.CustomAttributes is not None):
1532
1533PyObject *@self.export.Name@::getCustomAttributes(const char* /*attr*/) const
1534{
1535return nullptr;
1536}
1537
1538int @self.export.Name@::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
1539{
1540return 0;
1541}
1542-
1543
1544+ if (self.export.DescriptorGetter):
1545PyObject* @self.export.Name@::descriptorGetter(PyObject* self, PyObject* obj, PyObject* type)
1546{
1547PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1548return nullptr;
1549}
1550-
1551
1552+ if (self.export.DescriptorSetter):
1553int @self.export.Name@::descriptorSetter(PyObject* self, PyObject* obj, PyObject* value)
1554{
1555PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
1556return -1;
1557}
1558-
1559
1560"""
1561