"""Classes for writing ISC configuration files."""

def _write_indent(fh, indent):
    """Write whitespace to file.

    Args:
        fh: (file) file object
        indent: (int) number of tabs ('\t') to be written
    """

    for i in range(0, indent):
        fh.write('\t')

class _Conf(object):

    """Base class for configuration objects."""

    def __init__(self):
        self.elements = []  # list of Statement and Clause objects

    def add_element(self, element):
        """Add element to elements."""

        if not isinstance(element, _Element):
            raise TypeError('%s is not an _Element' % element)
        self.elements.append(element)

    def get_elements(self, label):
        """Return list of all items with label from elements."""

        return [e for e in self.elements if e.label == label]

    def remove_elements(self, label):
        """Remove all items with label from elements."""

        # modify list in situ
        self.elements[:] = [e for e in self.elements if e.label != label]

class ISCConf(_Conf):

    """Class for ISC software configuration.

    Intended for named, but effort has been made (but not tested) to
    accomodate dhcpd.
    """