1 import commands, os
2
3 _uncompress_table = {
4 ".bz": "bzip2",
5 ".BZ": "bzip2",
6 ".gz": "gzip",
7 ".GZ": "gzip",
8 ".Z": "compress",
9 }
10
12 ext = os.path.splitext(filename)[1]
13 type = _uncompress_table.get(ext)
14 if type is None:
15 return open(filename, mode)
16 if type == "gzip":
17 import gzip
18 gzip.open(filename, mode)
19 if type == "bzip2":
20 cmd = "bzcat --decompress"
21 cmd += commands.mkarg(filename)
22 return os.popen(cmd, mode)
23 if type == "compress":
24 cmd = "zcat -d"
25 cmd += commands.mkarg(filename)
26 return os.popen(cmd, mode)
27 raise AssertionError("What's a %r?" % type)
28