OpenQuizz
Une application de gestion des contenus pédagogiques
LoopContext Class Reference
Inheritance diagram for LoopContext:

Public Member Functions

def __init__ (self, iterable, undefined, recurse=None, depth0=0)
 
def length (self)
 
def __len__ (self)
 
def depth (self)
 
def index (self)
 
def revindex0 (self)
 
def revindex (self)
 
def first (self)
 
def last (self)
 
def previtem (self)
 
def nextitem (self)
 
def cycle (self, *args)
 
def changed (self, *value)
 
def __iter__ (self)
 
def __next__ (self)
 
def __call__ (self, iterable)
 
def __repr__ (self)
 

Data Fields

 depth0
 

Static Public Attributes

 index0
 

Detailed Description

A wrapper iterable for dynamic ``for`` loops, with information
about the loop and iteration.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  iterable,
  undefined,
  recurse = None,
  depth0 = 0 
)
:param iterable: Iterable to wrap.
:param undefined: :class:`Undefined` class to use for next and
    previous items.
:param recurse: The function to render the loop body when the
    loop is marked recursive.
:param depth0: Incremented when looping recursively.

Member Function Documentation

◆ __call__()

def __call__ (   self,
  iterable 
)
When iterating over nested data, render the body of the loop
recursively with the given inner iterable data.

The loop must have the ``recursive`` marker for this to work.

◆ __iter__()

def __iter__ (   self)

◆ __len__()

def __len__ (   self)

◆ __next__()

def __next__ (   self)

◆ __repr__()

def __repr__ (   self)

◆ changed()

def changed (   self,
value 
)
Return ``True`` if previously called with a different value
(including when called for the first time).

:param value: One or more values to compare to the last call.

◆ cycle()

def cycle (   self,
args 
)
Return a value from the given args, cycling through based on
the current :attr:`index0`.

:param args: One or more values to cycle through.

◆ depth()

def depth (   self)
How many levels deep a recursive loop currently is, starting at 1.

◆ first()

def first (   self)
Whether this is the first iteration of the loop.

◆ index()

def index (   self)
Current iteration of the loop, starting at 1.

◆ last()

def last (   self)
Whether this is the last iteration of the loop.

Causes the iterable to advance early. See
:func:`itertools.groupby` for issues this can cause.
The :func:`groupby` filter avoids that issue.

Reimplemented in AsyncLoopContext.

◆ length()

def length (   self)
Length of the iterable.

If the iterable is a generator or otherwise does not have a
size, it is eagerly evaluated to get a size.

Reimplemented in AsyncLoopContext.

◆ nextitem()

def nextitem (   self)
The item in the next iteration. Undefined during the last
iteration.

Causes the iterable to advance early. See
:func:`itertools.groupby` for issues this can cause.
The :func:`groupby` filter avoids that issue.

Reimplemented in AsyncLoopContext.

◆ previtem()

def previtem (   self)
The item in the previous iteration. Undefined during the
first iteration.

◆ revindex()

def revindex (   self)
Number of iterations from the end of the loop, ending at 1.

Requires calculating :attr:`length`.

Reimplemented in AsyncLoopContext.

◆ revindex0()

def revindex0 (   self)
Number of iterations from the end of the loop, ending at 0.

Requires calculating :attr:`length`.

Reimplemented in AsyncLoopContext.

Field Documentation

◆ depth0

depth0

◆ index0

index0
static

The documentation for this class was generated from the following file: