annotate Lib/UserDict.py @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents d6f6a1cb7d79
children 404ba017ad42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1416
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # A more or less complete user-defined wrapper around dictionary objects
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 class UserDict:
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 def __init__(self): self.data = {}
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 def __repr__(self): return repr(self.data)
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 def __cmp__(self, dict):
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 if type(dict) == type(self.data):
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 return cmp(self.data, dict)
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 else:
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 return cmp(self.data, dict.data)
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 def __len__(self): return len(self.data)
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 def __getitem__(self, key): return self.data[key]
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 def __setitem__(self, key, item): self.data[key] = item
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 def __delitem__(self, key): del self.data[key]
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 def keys(self): return self.data.keys()
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 def items(self): return self.data.items()
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 def values(self): return self.data.values()
d6f6a1cb7d79 * test_*.py: new lambda syntax (also affects tests for filter, map,
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 def has_key(self, key): return self.data.has_key(key)