Replacement for @raoulb pr#914

See #914

ToDo:
- [x] tests
- [x] final rebase
Oh I see your comment now that it gave import error. We'd have to use something like http://stackoverflow.com/a/5191224/161801 to make it a class property, which doesn't get evaluated until it is called. Not sure if it's worth it. You decide.