| Home | Trees | Indices | Help |
|---|
|
|
1 # indexed_dict.py 2 # Implements IndexedDictionary class. 3 # 4 # Copyright (C) 2009 Red Hat, Inc. 5 # 6 # This copyrighted material is made available to anyone wishing to use, 7 # modify, copy, or redistribute it subject to the terms and conditions of 8 # the GNU General Public License v.2, or (at your option) any later version. 9 # This program is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY expressed or implied, including the implied warranties of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 12 # Public License for more details. You should have received a copy of the 13 # GNU General Public License along with this program; if not, write to the 14 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 15 # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the 16 # source code or documentation are not subject to the GNU General Public 17 # License and may only be used or replicated with the express permission of 18 # Red Hat, Inc. 19 # 2022 """ Indexed dictionary that remembers order of the inserted elements. 23 24 Values can be inserted with string keys only, but referenced by both 25 string keys or index. 26 27 There's a unit test for the class, please maintain it along. 28 """ 324734 if type(key) is int: 35 key = self._indexes[key] 36 return super(IndexedDict, self).__getitem__(key)3739 if type(key) is int: 40 raise TypeError("IndexedDict only accepts strings as new keys") 41 assert(len(self) == len(self._indexes)) 42 self._indexes.append(key) 43 return super(IndexedDict, self).__setitem__(key, value)4446 return self._indexes.index(string_key)
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Mar 2 14:52:26 2012 | http://epydoc.sourceforge.net |