<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def count_all(self):
 """ Returns the total number of middleware in this chain and subchains. """

        return sum(x.func.count_all() if x.is_subchain else 1 for x in self)