annotate utils/odict.py @ 6:0427ca314f3d draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit d7b1a60c0aecc46b7f625c3e32f882562b512fd9
author devteam
date Mon, 13 Jun 2022 16:24:31 +0000
parents 7a2a604ae9c8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
1 """
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
2 Ordered dictionary implementation.
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
3 """
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
4
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
5 from UserDict import UserDict
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
6
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
7
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
8 class odict(UserDict):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
9 """
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
10 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
11
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
12 This dictionary class extends UserDict to record the order in which items are
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
13 added. Calling keys(), values(), items(), etc. will return results in this
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
14 order.
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
15 """
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
16 def __init__( self, dict=None ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
17 self._keys = []
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
18 UserDict.__init__( self, dict )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
19
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
20 def __delitem__( self, key ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
21 UserDict.__delitem__( self, key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
22 self._keys.remove( key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
23
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
24 def __setitem__( self, key, item ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
25 UserDict.__setitem__( self, key, item )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
26 if key not in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
27 self._keys.append( key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
28
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
29 def clear( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
30 UserDict.clear( self )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
31 self._keys = []
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
32
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
33 def copy(self):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
34 new = odict()
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
35 new.update( self )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
36 return new
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
37
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
38 def items( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
39 return zip( self._keys, self.values() )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
40
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
41 def keys( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
42 return self._keys[:]
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
43
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
44 def popitem( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
45 try:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
46 key = self._keys[-1]
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
47 except IndexError:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
48 raise KeyError( 'dictionary is empty' )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
49 val = self[ key ]
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
50 del self[ key ]
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
51 return ( key, val )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
52
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
53 def setdefault( self, key, failobj=None ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
54 if key not in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
55 self._keys.append( key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
56 return UserDict.setdefault( self, key, failobj )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
57
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
58 def update( self, dict ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
59 for ( key, val ) in dict.items():
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
60 self.__setitem__( key, val )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
61
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
62 def values( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
63 return map( self.get, self._keys )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
64
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
65 def iterkeys( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
66 return iter( self._keys )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
67
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
68 def itervalues( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
69 for key in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
70 yield self.get( key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
71
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
72 def iteritems( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
73 for key in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
74 yield key, self.get( key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
75
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
76 def __iter__( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
77 for key in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
78 yield key
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
79
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
80 def reverse( self ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
81 self._keys.reverse()
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
82
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
83 def insert( self, index, key, item ):
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
84 if key not in self._keys:
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
85 self._keys.insert( index, key )
7a2a604ae9c8 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/subtract commit 4e2052686dfe8003f867449e0affff96398b2a62
devteam
parents:
diff changeset
86 UserDict.__setitem__( self, key, item )