Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 43 lines (33 sloc) 1.069 kb
ec50b5a @mludvig - Added headers with copyright to all files
mludvig authored
1 ## Amazon S3 manager
2 ## Author: Michal Ludvig <michal@logix.cz>
3 ## http://www.logix.cz/michal
4 ## License: GPL Version 2
5
6 class BidirMap(object):
d439efb @mludvig ATTENTION -- Mega WhiteSpace conversion !!!
mludvig authored
7 def __init__(self, **map):
8 self.k2v = {}
9 self.v2k = {}
10 for key in map:
11 self.__setitem__(key, map[key])
12
13 def __setitem__(self, key, value):
14 if self.v2k.has_key(value):
15 if self.v2k[value] != key:
16 raise KeyError("Value '"+str(value)+"' already in use with key '"+str(self.v2k[value])+"'")
17 try:
18 del(self.v2k[self.k2v[key]])
19 except KeyError:
20 pass
21 self.k2v[key] = value
22 self.v2k[value] = key
23
24 def __getitem__(self, key):
25 return self.k2v[key]
26
27 def __str__(self):
28 return self.v2k.__str__()
29
30 def getkey(self, value):
31 return self.v2k[value]
32
33 def getvalue(self, key):
34 return self.k2v[key]
35
36 def keys(self):
37 return [key for key in self.k2v]
38
39 def values(self):
40 return [value for value in self.v2k]
41
42 # vim:et:ts=4:sts=4:ai
Something went wrong with that request. Please try again.