@@ -39,15 +39,25 @@ def _populate_indexes(self):
3939 self ._indexes ['alias' ] = _build_index ('alias' , self )
4040 self ._indexes ['caption' ] = _build_index ('caption' , self )
4141
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+
4250 def __setitem__ (self , key , value ):
51+ real_key = self ._get_real_key (key )
52+
4353 alias = _resolve_value ('alias' , value )
4454 caption = _resolve_value ('caption' , value )
4555 if alias is not None :
46- self ._indexes ['alias' ][alias ] = key
56+ self ._indexes ['alias' ][alias ] = real_key
4757 if caption is not None :
48- self ._indexes ['caption' ][caption ] = key
58+ self ._indexes ['caption' ][caption ] = real_key
4959
50- dict .__setitem__ (self , key , value )
60+ dict .__setitem__ (self , real_key , value )
5161
5262 def get (self , key , default_value = _no_default_value ):
5363 try :
@@ -58,9 +68,5 @@ def get(self, key, default_value=_no_default_value):
5868 raise
5969
6070 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