@contextmanager
def open_tar(path_or_file, *args, **kwargs):
 (path, fileobj) = ((path_or_file, None) if isinstance(path_or_file, string_types) else (None, path_or_file))
 with closing(TarFile.open(path, fileobj=fileobj, *args, **kwargs)) as tar:
  (yield tar)

@ contextmanager def open_tar ( path_or_file , * args , ** kwargs ) : ( path , fileobj ) = ( ( path_or_file , None ) if isinstance ( path_or_file , string_types ) else ( None , path_or_file ) ) with closing ( TarFile . open ( path , fileobj = fileobj , * args , ** kwargs ) ) as tar : ( yield tar )
a with-context for tar files .