code: def CsvToTable(self, buf, header=True, separator=","):
          
          self.Reset()
  
          header_row = self.row_class()
          if header:
              line = buf.readline()
              header_str = ""
              while not header_str:
                  # Remove comments.
                  header_str = line.split("#")[0].strip()
                  if not header_str:
                      line = buf.readline()
  
              header_list = header_str.split(separator)
              header_length = len(header_list)
  
              for entry in header_list:
                  entry = entry.strip()
                  if entry in header_row:
                      raise TableError("Duplicate header entry %r." % entry)
  
                  header_row[entry] = entry
              header_row.row = 0
              self._table[0] = header_row
  
          # xreadlines would be better but not supported by StringIO for testing.
          for line in buf:
              # Support commented lines, provide '#' is first character of line.
              if line.startswith("#"):
                  continue
  
              lst = line.split(separator)
              lst = [l.strip() for l in lst]
              if header and len(lst) != header_length:
                  # Silently drop illegal line entries
                  continue
              if not header:
                  header_row = self.row_class()
                  header_length = len(lst)
                  header_row.values = dict(
                      zip(range(header_length), range(header_length))
                  )
                  self._table[0] = header_row
                  header = True
                  continue
  
              new_row = self.NewRow()
              new_row.values = lst
              header_row.row = self.size + 1
              self._table.append(new_row)
  
          return self.size
docs: Parses buffer into tabular format.
  
      Strips off comments (preceded by '#').
      Optionally parses and indexes by first line (header).
  
      Args:
        buf: String file buffer containing CSV data.
        header: Is the first line of buffer a header.
        separator: String that CSV is separated by.
  
      Returns:
        int, the size of the table created.
  
      Raises:
        TableError: A parsing error occurred.