How to use the textfsm.texttable.Row function in textfsm

To help you get started, we’ve selected a few textfsm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / textfsm / textfsm / texttable.py View on Github external
TypeError: Argument is not a list or dict, or list is not equal row
      length or dictionary keys don't match.
    """

    def _ToStr(value):
      """Convert individul list entries to string."""
      if isinstance(value, (list, tuple)):
        result = []
        for val in value:
          result.append(str(val))
        return result
      else:
        return str(value)

    # Row with identical header can be copied directly.
    if isinstance(values, Row):
      if self._keys != values.header:
        raise TypeError('Attempt to append row with mismatched header.')
      self._values = copy.deepcopy(values.values)

    elif isinstance(values, dict):
      for key in self._keys:
        if key not in values:
          raise TypeError('Dictionary key mismatch with row.')
      for key in self._keys:
        self[key] = _ToStr(values[key])

    elif isinstance(values, list) or isinstance(values, tuple):
      if len(values) != len(self._values):
        raise TypeError('Supplied list length != row length')
      for (index, value) in enumerate(values):
        self._values[index] = _ToStr(value)
github google / textfsm / textfsm / texttable.py View on Github external
  def __init__(self, row_class=Row):
    """Initialises a new table.

    Args:
      row_class: A class to use as the row object. This should be a
        subclass of this module's Row() class.
    """
    self.row_class = row_class
    self.separator = ', '
    self.Reset()
github google / textfsm / textfsm / texttable.py View on Github external
def __init__(self, *args, **kwargs):
    super(Row, self).__init__(*args, **kwargs)
    self._keys = list()
    self._values = list()
    self.row = None
    self.table = None
    self._color = None
    self._index = {}
github google / textfsm / textfsm / texttable.py View on Github external
Args:
      key: string for header value.
      value: string for a data value.
      row_index: Offset into row for data.

    Raises:
      IndexError: If the offset is out of bands.
    """
    if row_index < 0:
      row_index += len(self)

    if not 0 <= row_index < len(self):
      raise IndexError('Index "%s" is out of bounds.' % row_index)

    new_row = Row()
    for idx in self.header:
      if self.index(idx) == row_index:
        new_row[key] = value
      new_row[idx] = self[idx]
    self._keys = new_row.header
    self._values = new_row.values
    del new_row
    self._BuildIndex()