From 121be3d9cf9107ebc487eb42412e62994e6a7db4 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 16 Oct 2003 19:40:14 +0000 Subject: [PATCH] Made the constructor take dictionaries. --- src/structures.py | 4 ++++ test/test_structures.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/structures.py b/src/structures.py index dd0e622a9..8c6f05c98 100644 --- a/src/structures.py +++ b/src/structures.py @@ -321,6 +321,10 @@ class MaxLengthQueue(queue): class TwoWayDictionary(dict): __slots__ = () def __init__(self, seq=(), **kwargs): + if hasattr(seq, 'iteritems'): + seq = seq.iteritems() + elif hasattr(seq, 'items'): + seq = seq.items() for (key, value) in seq: self[key] = value self[value] = key diff --git a/test/test_structures.py b/test/test_structures.py index 497867f59..ad92ee81d 100644 --- a/test/test_structures.py +++ b/test/test_structures.py @@ -555,6 +555,10 @@ class TwoWayDictionaryTestCase(unittest.TestCase): self.failUnless('foo' in d) self.failUnless('bar' in d) + d = TwoWayDictionary({1: 2}) + self.failUnless(1 in d) + self.failUnless(2 in d) + def testSetitem(self): d = TwoWayDictionary() d['foo'] = 'bar'