code: def get_tar_mode (compression):
      
      if compression == 'gzip':
          return 'w:gz'
      if compression == 'bzip2':
          return 'w:bz2'
      if compression == 'lzma' and py_lzma:
          return 'w:xz'
      if compression:
          msg = 'pytarfile does not support %s for tar compression'
          raise util.PatoolError(msg % compression)
      # no compression
      return 'w'
docs: Determine tarfile open mode according to the given compression.