# HG changeset patch # User cmlenz # Date 1174324860 0 # Node ID aa32588342ae3b87f100c2712977d7b3a3a9225d # Parent e41c8cff992f93bd8b2ea712d66b52010441c2db Add support for `len()` to the `Context` class. diff --git a/genshi/template/base.py b/genshi/template/base.py --- a/genshi/template/base.py +++ b/genshi/template/base.py @@ -127,6 +127,10 @@ raise KeyError(key) return value + def __len__(self): + """Return the number of distinctly named variables in the context.""" + return len(self.items()) + def __setitem__(self, key, value): """Set a variable in the current scope.""" self.frames[0][key] = value