Skip to content

Commit

Permalink
[section] Add extend method
Browse files Browse the repository at this point in the history
Closes G-Node#237
  • Loading branch information
mpsonntag committed Mar 27, 2018
1 parent 84d99e3 commit c2f32e3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions odml/section.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8
import collections
import uuid

from . import base
Expand Down Expand Up @@ -274,6 +275,25 @@ def append(self, *obj_tuple):
for obj in obj_tuple:
self.__append(obj)

def extend(self, obj_list):
"""
Method adds Sections and Properties to the respective child-lists
of the current section.
:param obj_list: Iterable containing Section and Property entries.
"""
if not isinstance(obj_list, collections.Iterable):
raise TypeError("'%s' object is not iterable" % type(obj_list).__name__)

# Make sure only Sections and Properties will be added.
for obj in obj_list:
if not isinstance(obj, Section) and not isinstance(obj, Property):
raise ValueError("odml.Section.extend: "
"Can only extend sections and properties.")

for obj in obj_list:
self.append(obj)

def insert(self, position, obj):
"""
Insert a Section or Property at the respective position
Expand Down

0 comments on commit c2f32e3

Please # to comment.