@@ -39,15 +39,25 @@ def _populate_indexes(self):
39
39
self ._indexes ['alias' ] = _build_index ('alias' , self )
40
40
self ._indexes ['caption' ] = _build_index ('caption' , self )
41
41
42
+ def _get_real_key (self , key ):
43
+ if key in self ._indexes ['alias' ]:
44
+ return self ._indexes ['alias' ][key ]
45
+ if key in self ._indexes ['caption' ]:
46
+ return self ._indexes ['caption' ][key ]
47
+
48
+ return key
49
+
42
50
def __setitem__ (self , key , value ):
51
+ real_key = self ._get_real_key (key )
52
+
43
53
alias = _resolve_value ('alias' , value )
44
54
caption = _resolve_value ('caption' , value )
45
55
if alias is not None :
46
- self ._indexes ['alias' ][alias ] = key
56
+ self ._indexes ['alias' ][alias ] = real_key
47
57
if caption is not None :
48
- self ._indexes ['caption' ][caption ] = key
58
+ self ._indexes ['caption' ][caption ] = real_key
49
59
50
- dict .__setitem__ (self , key , value )
60
+ dict .__setitem__ (self , real_key , value )
51
61
52
62
def get (self , key , default_value = _no_default_value ):
53
63
try :
@@ -58,9 +68,5 @@ def get(self, key, default_value=_no_default_value):
58
68
raise
59
69
60
70
def __getitem__ (self , key ):
61
- if key in self ._indexes ['alias' ]:
62
- key = self ._indexes ['alias' ][key ]
63
- elif key in self ._indexes ['caption' ]:
64
- key = self ._indexes ['caption' ][key ]
65
-
66
- return dict .__getitem__ (self , key )
71
+ real_key = self ._get_real_key (key )
72
+ return dict .__getitem__ (self , real_key )
0 commit comments