summaryrefslogtreecommitdiff
path: root/lib/git/utils.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-13 19:35:49 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-13 19:35:49 +0200
commitf4fa1cb3c3e84cad8b74edb28531d2e27508be26 (patch)
tree1b370c702e2c92251c2773deeb6fa136562dd7ef /lib/git/utils.py
parent5eb0f2c241718bc7462be44e5e8e1e36e35f9b15 (diff)
downloadgitpython-f4fa1cb3c3e84cad8b74edb28531d2e27508be26.tar.gz
Added base for all iteratable objects
Diffstat (limited to 'lib/git/utils.py')
-rw-r--r--lib/git/utils.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/git/utils.py b/lib/git/utils.py
index 39994bd5..96ec15b9 100644
--- a/lib/git/utils.py
+++ b/lib/git/utils.py
@@ -27,6 +27,12 @@ def is_git_dir(d):
class LazyMixin(object):
+ """
+ Base class providing an interface to lazily retrieve attribute values upon
+ first access. If slots are used, memory will only be reserved once the attribute
+ is actually accessed and retrieved the first time. All future accesses will
+ return the cached value as stored in the Instance's dict or slot.
+ """
__slots__ = tuple()
def __getattr__(self, attr):
@@ -49,3 +55,35 @@ class LazyMixin(object):
in the single attribute."""
pass
+
+class Iterable(object):
+ """
+ Defines an interface for iterable items which is to assure a uniform
+ way to retrieve and iterate items within the git repository
+ """
+ __slots__ = tuple()
+
+ @classmethod
+ def list_items(cls, repo, *args, **kwargs):
+ """
+ Find all items of this type - subclasses can specify args and kwargs differently.
+ If no args are given, subclasses are obliged to return all items if no additional
+ arguments arg given.
+
+ Note: Favor the iter_items method as it will
+
+ Returns:
+ list(Item,...) list of item instances
+ """
+ return list(cls.iter_items, repo, *args, **kwargs)
+
+
+ @classmethod
+ def iter_items(cls, repo, *args, **kwargs):
+ """
+ For more information about the arguments, see find_all
+ Return:
+ iterator yielding Items
+ """
+ raise NotImplementedError("To be implemented by Subclass")
+