Simplified logic and made some assumptions:
 - the gzip module should always be available, so there is no need to test the import
 - mode flags are difficult to get right across platforms and are low priority at the moment.
The end result is a simpler snippet that does a dictionary lookup to find the right file "open"er.