import re


def PartitionCSVLine(line):
  """Returns a list of all column values in a comma-separated-value line.

  Args:
    line: The input line from a comma-separated-value source.

  Returns:
    CSV files may include quoted text segments containing commas.  This
    routine will return an array of all of the columns present in the line,
     respecting quoted regions.
  """

  # This routine is more complicated than expected due to the presence of
  # quoted lists within colums.  The algorithm proceeds by first splitting
  # the line by quoted sub-strings.  Sub-strings not matching a quoted
  # expression are then split on ','.
  quoted_column = re.compile('(\"[^\"]*\")')
  block_partitions = quoted_column.split(line)

  output_columns = []

  for chunk in block_partitions:
    # If this chunk is a quoted string, append it to the output verbatim.
    if quoted_column.match(chunk):
      output_columns += [chunk]
    else:
      output_columns += chunk.split(',')
  
  # Return the output set of columns with all empty entries removed.
  # Empty columns will be present due to the interaction of the split by
  # quoted string, and split by ','.
  # For example:  here, is, "a (tuple, example)", to, try
  # After the first split: ['here, is, ', 'a (tuple, example)', 'to, try']
  # After the second split:
  #  ['here', 'is', '', 'a (tuple, example)', 'to', 'try']
  # Since these empty columns are not present in the original list, we remove
  # them here.
  return [(column) for column in output_columns if column != ""]