Commit 02903f10 authored by De Boissieu Florian's avatar De Boissieu Florian

add class checkers and copy method

branch : settersOptions
parent 147dff8f
......@@ -4743,7 +4743,7 @@ def getValidatorBody(stName, base, element, child):
# Generate get/set/add/insert member functions.
def generateGettersAndSetters(wrt, element):
def generateGettersAndSetters(wrt, prefix, element):
for child in element.getChildren():
if child.getType() == AnyTypeIdentifier:
wrt(' def get_anytypeobjs_(self): return self.anytypeobjs_\n')
......@@ -4764,6 +4764,7 @@ def generateGettersAndSetters(wrt, element):
wrt(' def get%s(self): return self.%s\n' % (capName, varname))
wrt(' def set%s(self, value):\n' % (capName))
wrt(' if value is not None:\n')
wrt(' checkclass(value, {})\n'.format(prefix+child.attrs['type']))
if child.getType() == SequenceType:
wrt(' for v in value\n')
wrt(' v.parent = self\n')
......@@ -4817,7 +4818,7 @@ def generateGettersAndSetters(wrt, element):
# wrt(' %sProp = property(get%s, set%s)\n' %
# (name, gsName, gsName))
wrt(' %s = property(get%s, set%s)\n' %
(name, gsName, gsName))
(mappedName, gsName, gsName))
if element.getSimpleContent() or element.isMixed():
wrt(' def get%s_(self): return self.valueOf_\n' % (
make_gs_name('valueOf'), ))
......@@ -5012,6 +5013,10 @@ def generateUserMethods(wrt, element):
source = spec.get_interpolated_source(values_dict)
def generateCopy(wrt, element):
wrt(' def copy(self):\n'
' obj_ = self.factory()\n'
' return(\n')
def generateHascontentMethod(wrt, prefix, element):
wrt(' def hasContent_(self):\n')
......@@ -5135,7 +5140,8 @@ def generateClasses(wrt, prefix, element, delayed, nameSpacesDef=''):
wrt(FactoryMethodTemplate.format(prefix=prefix, name=name))
wrt(' factory = staticmethod(factory)\n')
if UseGetterSetter != 'none':
generateGettersAndSetters(wrt, element)
generateGettersAndSetters(wrt, prefix, element)
generateCopy(wrt, element)
generateValidatorDefs(wrt, element)
if element.namespace:
namespace = element.namespace
......@@ -5293,6 +5299,14 @@ CurrentSubclassModule_ = None
# Support/utility functions.
def checkclass(value, cl):
if isinstance(value, list):
for v in value:
if not isinstance(v, cl):
raise ValueError("invalid class")
if not isinstance(value, cl):
raise ValueError("invalid class")
def showIndent(outfile, level, pretty_print=True):
if pretty_print:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment