# HG changeset patch # User Søren Løvborg # Date 2017-02-14 21:14:40 # Node ID c72fe7e3b17f0c8b88a4e8fd4828f72ef2b7eac7 # Parent fffb4e73700e2c81214139c7a44b7d20fd06c3e3 vcs: replace deprecated __getslice__ with __getitem__ __getslice__ has been deprecated since Python 2.0. The support for single item indexing is currently unused, but was trivial to implement (and needed for proper __getitem__ support). diff --git a/kallithea/lib/vcs/backends/base.py b/kallithea/lib/vcs/backends/base.py --- a/kallithea/lib/vcs/backends/base.py +++ b/kallithea/lib/vcs/backends/base.py @@ -1051,12 +1051,13 @@ class CollectionGenerator(object): for rev in self.revs: yield self.repo.get_changeset(rev) - def __getslice__(self, i, j): - """ - Returns a iterator of sliced repository - """ - sliced_revs = self.revs[i:j] - return CollectionGenerator(self.repo, sliced_revs) + def __getitem__(self, what): + """Return either a single element by index, or a sliced collection.""" + if isinstance(what, slice): + return CollectionGenerator(self.repo, self.revs[what]) + else: + # single item + return self.repo.get_changeset(self.revs[what]) def __repr__(self): return '' % (len(self))