def parse(self, stream, graph=None):

        def open_file_for_parse(filename):
            if sys.version_info[:2] >= (3, 0):
                return codecs.open(filename, "r", "utf-8")
            else:
                return open(filename, "r")

        def do_parse(stream, graph):
            filename = stream.name
            context = stream.read()
            #self.graf_validator.validate_xml(context, annotation="True")

            parser = make_parser()
            handler = GraphHandler(parser, graph, parse_dependency,
                                   parse_anchor=self._parse_anchor,
                                   constants=self._g)
            parser.setContentHandler(handler)
            parser.parse(filename)

        def parse_dependency(name, graph):
            if name in parsed_deps:
                return
            parsed_deps.add(name)
            do_parse(get_dependency(name), graph)

        if not hasattr(stream, 'read'):
            stream = open_file_for_parse(stream)

        parsed_deps = set()
        extension = os.path.splitext(stream.name)[1][1:]

        if extension == 'hdr':
            context = stream.read()
            #self.graf_validator.validate_xml(context, header=True)

            doc_header = minidom.parseString(context)
            dirname = os.path.dirname(stream.name)

            if self._get_dep:
                get_dependency = self._get_dep
            else:
                header = DocumentHeader(stream.name)
                for annotation in doc_header.getElementsByTagName('annotation'):
                    loc = annotation.getAttribute('loc')
                    fid = annotation.getAttribute('f.id')
                    header.add_type(fid, loc)

                def get_dependency(name):
                    return open_file_for_parse(os.path.join(dirname, header.get_location(name)))


            for annotation in doc_header.getElementsByTagName('annotation'):
                loc = annotation.getAttribute('loc')
                fid = annotation.getAttribute('f.id')

                if fid in parsed_deps:
                    continue

                if graph is None:
                    graph = Graph()

                stream = open_file_for_parse(os.path.join(dirname, loc))
                do_parse(stream, graph)
        else:
            if self._get_dep:
                get_dependency = self._get_dep
            else:
                # Default get_dependency is relative to path
                header = DocumentHeader(os.path.abspath(stream.name))

                def get_dependency(name):
                    return open_file_for_parse(header.get_location(name))

            if graph is None:
                graph = Graph()

            do_parse(stream, graph)

        self._parsed_deps = parsed_deps

        return graph
Test initialize the config file
dataset/ETHPy150Open cidles/graf-python/src/graf/io.py/GraphParser.parse--crossover with--dataset/ETHPy150Open ganeti/ganeti/test/py/ganeti.config_unittest.py/TestConfigRunner.testInit