From 63a71baae6fab9e8a59d82a7158549d63c2c58cf Mon Sep 17 00:00:00 2001 From: calvin Date: Tue, 29 Mar 2005 11:30:47 +0000 Subject: [PATCH] add get_true method to ListDict git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2471 e7d03fd6-7b0d-0410-9947-9c21f3af8025 --- linkcheck/containers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linkcheck/containers.py b/linkcheck/containers.py index 8ae0f71a..441bc6c2 100644 --- a/linkcheck/containers.py +++ b/linkcheck/containers.py @@ -133,6 +133,15 @@ class ListDict (dict): self._keys = [] super(ListDict, self).clear() + def get_true (self, key, default): + """ + Reteurn default element if key is not in the dict, of if the + self[key] evaluates to False. + """ + if key not in self or not self[key]: + return default + return self[key] + class Node (object): """