@@ -54,7 +54,6 @@ class BaseSection(base.Sectionable):
54
54
"""
55
55
56
56
type = None
57
- reference = None # the *import* property
58
57
_link = None
59
58
_include = None
60
59
_merged = None
@@ -328,7 +327,8 @@ def parent(self):
328
327
def parent (self , new_parent ):
329
328
if new_parent is None and self ._parent is None :
330
329
return
331
- elif new_parent is None and self ._parent is not None :
330
+
331
+ if new_parent is None and self ._parent is not None :
332
332
self ._parent .remove (self )
333
333
self ._parent = None
334
334
elif self ._validate_parent (new_parent ):
@@ -341,7 +341,8 @@ def parent(self, new_parent):
341
341
"odml.Section.parent: passed value is not of consistent type!"
342
342
"\n odml.Document or odml.Section expected" )
343
343
344
- def _validate_parent (self , new_parent ):
344
+ @staticmethod
345
+ def _validate_parent (new_parent ):
345
346
"""
346
347
Checks whether a provided object is a valid odml.Section or odml.Document..
347
348
@@ -402,9 +403,9 @@ def set_sections_cardinality(self, min_val=None, max_val=None):
402
403
Sets the Sections cardinality of a Section.
403
404
404
405
:param min_val: Required minimal number of values elements. None denotes
405
- no restrictions on values elements minimum. Default is None.
406
+ no restrictions on sections elements minimum. Default is None.
406
407
:param max_val: Allowed maximal number of values elements. None denotes
407
- no restrictions on values elements maximum. Default is None.
408
+ no restrictions on sections elements maximum. Default is None.
408
409
"""
409
410
self .sec_cardinality = (min_val , max_val )
410
411
@@ -455,9 +456,9 @@ def set_properties_cardinality(self, min_val=None, max_val=None):
455
456
Sets the Properties cardinality of a Section.
456
457
457
458
:param min_val: Required minimal number of values elements. None denotes
458
- no restrictions on values elements minimum. Default is None.
459
+ no restrictions on properties elements minimum. Default is None.
459
460
:param max_val: Allowed maximal number of values elements. None denotes
460
- no restrictions on values elements maximum. Default is None.
461
+ no restrictions on properties elements maximum. Default is None.
461
462
"""
462
463
self .prop_cardinality = (min_val , max_val )
463
464
@@ -521,16 +522,16 @@ def extend(self, obj_list):
521
522
# Make sure only Sections and Properties with unique names will be added.
522
523
for obj in obj_list :
523
524
if not isinstance (obj , BaseSection ) and not isinstance (obj , BaseProperty ):
524
- raise ValueError ( "odml.Section.extend: "
525
- "Can only extend sections and properties." )
525
+ msg = "odml.Section.extend: Can only extend sections and properties. "
526
+ raise ValueError ( msg )
526
527
527
- elif isinstance (obj , BaseSection ) and obj .name in self .sections :
528
- raise KeyError ( "odml.Section.extend: "
529
- "Section with name '%s' already exists." % obj . name )
528
+ if isinstance (obj , BaseSection ) and obj .name in self .sections :
529
+ msg = "odml.Section.extend: Section with name '%s' already exists." % obj . name
530
+ raise KeyError ( msg )
530
531
531
- elif isinstance (obj , BaseProperty ) and obj .name in self .properties :
532
- raise KeyError ( "odml.Section.extend: "
533
- "Property with name '%s' already exists." % obj . name )
532
+ if isinstance (obj , BaseProperty ) and obj .name in self .properties :
533
+ msg = "odml.Section.extend: Property with name '%s' already exists." % obj . name
534
+ raise KeyError ( msg )
534
535
535
536
for obj in obj_list :
536
537
self .append (obj )
@@ -613,13 +614,14 @@ def contains(self, obj):
613
614
if isinstance (obj , BaseSection ):
614
615
return super (BaseSection , self ).contains (obj )
615
616
616
- elif isinstance (obj , BaseProperty ):
617
+ if isinstance (obj , BaseProperty ):
617
618
for i in self ._props :
618
619
if obj .name == i .name :
619
620
return i
620
- else :
621
- raise ValueError ("odml.Section.contains:"
622
- "Section or Property object expected." )
621
+
622
+ return None
623
+
624
+ raise ValueError ("odml.Section.contains: Section or Property object expected." )
623
625
624
626
def merge_check (self , source_section , strict = True ):
625
627
"""
0 commit comments