code: def get_file_mode_for_writing(context):
      
      format = context['tar'].get('format', None)
      # slightly weird double-check because falsy format could mean either format
      # doesn't exist in input, OR that it exists and is empty. Exists-but-empty
      # has special meaning - default to no compression.
      if format or format == '':
          mode = f"w:{context.get_formatted_string(format)}"
      else:
          mode = 'w:xz'
  
      return mode
docs: Get file mode for writing from tar['format'].
  
      This should return w:, w:gz, w:bz2 or w:xz. If user specified something
      wacky in tar.Format, that's their business.