@@ -332,6 +332,21 @@ def _add_list_getter(self):
332332 def _add_method_name (self ):
333333 return '_add_%s' % self ._prop_name
334334
335+ def _add_public_adder (self ):
336+ """
337+ Add a public ``add_x()`` method to the parent element class.
338+ """
339+ def add_child (obj ):
340+ private_add_method = getattr (obj , self ._add_method_name )
341+ child = private_add_method ()
342+ return child
343+
344+ add_child .__doc__ = (
345+ 'Add a new ``<%s>`` child element unconditionally, inserted in t'
346+ 'he correct sequence.' % self ._nsptagname
347+ )
348+ self ._add_to_class (self ._public_add_method_name , add_child )
349+
335350 def _add_to_class (self , name , method ):
336351 """
337352 Add *method* to the target class as *name*, unless *name* is already
@@ -384,6 +399,16 @@ def get_child_element_list(obj):
384399 )
385400 return get_child_element_list
386401
402+ @lazyproperty
403+ def _public_add_method_name (self ):
404+ """
405+ add_childElement() is public API for a repeating element, allowing
406+ new elements to be added to the sequence. May be overridden to
407+ provide a friendlier API to clients having domain appropriate
408+ parameter names for required attributes.
409+ """
410+ return 'add_%s' % self ._prop_name
411+
387412 @lazyproperty
388413 def _remove_method_name (self ):
389414 return '_remove_%s' % self ._prop_name
@@ -519,31 +544,6 @@ def populate_class_members(self, element_cls, prop_name):
519544 self ._add_public_adder ()
520545 delattr (element_cls , prop_name )
521546
522- def _add_public_adder (self ):
523- """
524- Add a public ``add_x()`` method to the parent element class.
525- """
526- def add_child (obj ):
527- private_add_method = getattr (obj , self ._add_method_name )
528- child = private_add_method ()
529- return child
530-
531- add_child .__doc__ = (
532- 'Add a new ``<%s>`` child element unconditionally, inserted in t'
533- 'he correct sequence.' % self ._nsptagname
534- )
535- self ._add_to_class (self ._public_add_method_name , add_child )
536-
537- @lazyproperty
538- def _public_add_method_name (self ):
539- """
540- add_childElement() is public API for a repeating element, allowing
541- new elements to be added to the sequence. May be overridden to
542- provide a friendlier API to clients having domain appropriate
543- parameter names for required attributes.
544- """
545- return 'add_%s' % self ._prop_name
546-
547547
548548class ZeroOrMore (_BaseChildElement ):
549549 """
@@ -560,6 +560,7 @@ def populate_class_members(self, element_cls, prop_name):
560560 self ._add_creator ()
561561 self ._add_inserter ()
562562 self ._add_adder ()
563+ self ._add_public_adder ()
563564 delattr (element_cls , prop_name )
564565
565566
0 commit comments