# Path: pyfits/util.py
# def indent(s, shift=1, width=4):
#     indented = '\n'.join(' ' * (width * shift) + l if l else ''
#                          for l in s.splitlines())
#     if s[-1] == '\n':
#         indented += '\n'
# 
#     return indented


import warnings
from .extern.six import next
from .util import indent


class _ErrList(list):
    """
    Verification errors list class.  It has a nested list structure
    constructed by error messages generated by verifications at
    different class levels.
    """

    def __new__(cls, val=None, unit='Element'):
        return super(cls, cls).__new__(cls, val)

    def __init__(self, val=None, unit='Element'):
        self.unit = unit

    def __str__(self):
        return '\n'.join(item[1] for item in self.iter_lines())

    def iter_lines(self, filter=None, shift=0):
        """
        Iterate the nested structure as a list of strings with appropriate
        indentations for each level of structure.
        """

        element = 0
        # go through the list twice, first time print out all top level
        # messages
        for item in self:
            if not isinstance(item, _ErrList):
                if filter is None or filter(item):

# Path: pyfits/util.py
# def indent(s, shift=1, width=4):
#     indented = '\n'.join(' ' * (width * shift) + l if l else ''
#                          for l in s.splitlines())
#     if s[-1] == '\n':
#         indented += '\n'
# 
#     return indented


# Path: pyfits/verify.py
import warnings
from .extern.six import next
from .util import indent



class _ErrList(list):
    """
    Verification errors list class.  It has a nested list structure
    constructed by error messages generated by verifications at
    different class levels.
    """

    def __new__(cls, val=None, unit='Element'):
        return super(cls, cls).__new__(cls, val)

    def __init__(self, val=None, unit='Element'):
        self.unit = unit

    def __str__(self):
        return '\n'.join(item[1] for item in self.iter_lines())

    def iter_lines(self, filter=None, shift=0):
        """
        Iterate the nested structure as a list of strings with appropriate
        indentations for each level of structure.
        """

        element = 0
        # go through the list twice, first time print out all top level
        # messages
        for item in self:
            if not isinstance(item, _ErrList):
                if filter is None or filter(item):

                    yield item[0], indent(item[1], shift=shift)