Python 2.5 compatibility: dynamic exception matching