summaryrefslogtreecommitdiff
path: root/git/util.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2011-06-08 10:43:47 +0200
committerSebastian Thiel <byronimo@gmail.com>2011-06-08 11:01:37 +0200
commitee9d6b97ad7d7bf6761161dc411258f2aa86d8c0 (patch)
tree24ca6faef1d8983dd43c3c6d54ba344025fef256 /git/util.py
parent4772fe04c38d2d0bd75d6a0f9d5905ee3ee08ae6 (diff)
downloadgitpython-ee9d6b97ad7d7bf6761161dc411258f2aa86d8c0.tar.gz
util: Added test for iterable list, and implemented __contains__ and __del__ functionality
Diffstat (limited to 'git/util.py')
-rw-r--r--git/util.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/git/util.py b/git/util.py
index d248b1ee..01940763 100644
--- a/git/util.py
+++ b/git/util.py
@@ -734,6 +734,21 @@ class IterableList(list):
raise ValueError("First parameter must be a string identifying the name-property. Extend the list after initialization")
# END help debugging !
+ def __contains__(self, attr):
+ # first try identy match for performance
+ rval = list.__contains__(self, attr)
+ if rval:
+ return rval
+ #END handle match
+
+ # otherwise make a full name search
+ try:
+ getattr(self, attr)
+ return True
+ except (AttributeError, TypeError):
+ return False
+ #END handle membership
+
def __getattr__(self, attr):
attr = self._prefix + attr
for item in self:
@@ -750,7 +765,24 @@ class IterableList(list):
return getattr(self, index)
except AttributeError:
raise IndexError( "No item found with id %r" % (self._prefix + index) )
+ # END handle getattr
+ def __delitem__(self, index):
+ delindex = index
+ if not isinstance(index, int):
+ delindex = -1
+ name = self._prefix + index
+ for i, item in enumerate(self):
+ if getattr(item, self._id_attr) == name:
+ delindex = i
+ break
+ #END search index
+ #END for each item
+ if delindex == -1:
+ raise IndexError("Item with name %s not found" % name)
+ #END handle error
+ #END get index to delete
+ list.__delitem__(self, delindex)
#} END utilities