<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse(self, file, outfile=None):
 """Parse a line-oriented entity file into a list of entity dict objects Note the returned list is of dict objects. TODO: These will later be specified using marshmallow and it should be possible to generate objects Arguments --------- file : file or string The file is parsed into entity objects. Can be a http URL, filename or `file-like-object`, for input assoc file outfile : file Optional output file in which processed lines are written. This a file or `file-like-object` Return ------ list Entities generated from the file """

        file = self._ensure_file(file)
        ents = []
        skipped = []
        n_lines = 0
        for line in file:
            n_lines += 1
            if line.startswith("!"):
                if outfile is not None:
                    outfile.write(line)
                continue
            line = line.strip("\n")
            if line == "":
                logging.warning("EMPTY LINE")
                continue

            parsed_line, new_ents  = self.parse_line(line)
            if self._skipping_line(new_ents): # Skip if there were no ents
                logging.warning("SKIPPING: {}".format(line))
                skipped.append(line)
            else:
                ents += new_ents
                if outfile is not None:
                    outfile.write(parsed_line + "\n")

        self.report.skipped += len(skipped)
        self.report.n_lines += n_lines
        #self.report.n_associations += len(ents)
        logging.info("Parsed {} ents from {} lines. Skipped: {}".
                     format(len(ents),
                            n_lines,
                            len(skipped)))
        file.close()
        return ents