示例#1
0
    def __init__(self, file, **kw):
        """
        ## This is an InputAsset file, created because you tried to pass a
        ## non-existent filename to a test.
        ##
        ## To use this file, place one input to be tested per line. Each
        ## test takes different inputs. Lines which are commented out with
        ## a '#' are not used.
        """
        self.file    = file
        self.eof     = False
        self.all     = Storage()

        for key, value in input_dict:
            self.all[key] = value

        try:
            self.handler = open(self.file, 'r')
        except IOError:
            with open(self.file, 'w') as explain:
                for line in self.__init__.__doc__:
                    explain.writeline(line)
            self.handler = open(self.file, 'r')
        try:
            assert isinstance(self.handler, file), "That's not a file!"
        except AssertionError, ae:
            log.err(ae)
示例#2
0
    def parse_line(self, line):
        """
        Override this method if you need line by line parsing of an Asset.

        The default parsing action is to ignore lines which are commented out
        with a '#', and to strip the newline character from the end of the
        line.

        If the line was commented out return an empty string instead.

        If a subclass Foo incorporates another class Bar, when Bar is not
        also a subclass of InputFile, and Bar.parse_line() exists, then
        do not overwrite Bar's parse_line method.
        """
        assert not hasattr(super(InputFile, self), 'parse_line')

        if self.parser is None:
            if not line.startswith('#'):
                return line.replace('\n', '')
            else:
                return ''
        else:
            try:
                assert isinstance(self.parser, FunctionType),"Not a function!"
            except AssertionError, ae:
                log.err(ae)
            else: