#NEWLINE# def openz( path , mode = 'rb' , closing = True ) : #NEWLINE# #INDENT# 'Open a file, transparently [de]compressing it if a known extension is present.' #NEWLINE# ( _ , extension ) = os . path . splitext ( path ) #NEWLINE# if ( extension == '.bz2' ) : #NEWLINE# #INDENT# file_ = bz2 . BZ2File ( path , mode ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( extension == '.gz' ) : #NEWLINE# #INDENT# file_ = gzip . GzipFile ( path , mode ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( extension == '.xz' ) : #NEWLINE# #INDENT# raise NotImplementedError ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return open ( path , mode ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if closing : #NEWLINE# #INDENT# return contextlib . closing ( file_ )