A cycle helper for templates.
| 572 | |
| 573 | @implements_iterator |
| 574 | class Cycler(object): |
| 575 | """A cycle helper for templates.""" |
| 576 | |
| 577 | def __init__(self, *items): |
| 578 | if not items: |
| 579 | raise RuntimeError('at least one item has to be provided') |
| 580 | self.items = items |
| 581 | self.reset() |
| 582 | |
| 583 | def reset(self): |
| 584 | """Resets the cycle.""" |
| 585 | self.pos = 0 |
| 586 | |
| 587 | @property |
| 588 | def current(self): |
| 589 | """Returns the current item.""" |
| 590 | return self.items[self.pos] |
| 591 | |
| 592 | def next(self): |
| 593 | """Goes one item ahead and returns it.""" |
| 594 | rv = self.current |
| 595 | self.pos = (self.pos + 1) % len(self.items) |
| 596 | return rv |
| 597 | |
| 598 | __next__ = next |
| 599 | |
| 600 | |
| 601 | class Joiner(object): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…