else:
return self._normal.setdefault(cp, default)
- def get(self, cp):
+ def __getitem__(self, cp):
+
+ if not isinstance(cp, basestring):
+ raise KeyError(cp)
+
ret = self._value_class()
normal_match = self._normal.get(cp)
+ match = False
+
if normal_match is not None:
+ match = True
if hasattr(ret, "update"):
ret.update(normal_match)
elif hasattr(ret, "extend"):
else:
raise NotImplementedError()
- for extended_cp in self._extended:
- if extended_cp_match(extended_cp, cp):
+ if '*' in cp:
+ v = self._extended.get(cp)
+ if v is not None:
+ match = True
if hasattr(ret, "update"):
- ret.update(self._extended[extended_cp])
+ ret.update(v)
elif hasattr(ret, "extend"):
- ret.extend(self._extended[extended_cp])
+ ret.extend(v)
else:
raise NotImplementedError()
+ else:
+ for extended_cp in self._extended:
+ if extended_cp_match(extended_cp, cp):
+ match = True
+ if hasattr(ret, "update"):
+ ret.update(self._extended[extended_cp])
+ elif hasattr(ret, "extend"):
+ ret.extend(self._extended[extended_cp])
+ else:
+ raise NotImplementedError()
+
+ if not match:
+ raise KeyError(cp)
return ret
else:
self._normal[cp] = val
- def __getitem__(self, cp):
- if not isinstance(cp, basestring):
- raise KeyError(cp)
- if "*" in cp:
- return self._extended[cp]
- else:
- return self._normal[cp]
-
def clear(self):
self._extended.clear()
self._normal.clear()
self.assertEqual(d.get("dev-libs/A"), { "test1": "x", "test2": "y" })
self.assertEqual(d.get("sys-apps/portage"), { "test1": "x", "test3": "z" })
self.assertEqual(d["dev-libs/*"], { "test2": "y" })
- self.assertEqual(d["sys-apps/portage"], { "test3": "z" })
+ self.assertEqual(d["sys-apps/portage"], {'test1': 'x', 'test3': 'z'})