'Flush the current set of URLs to the output.  This is a little
slow because we like to sort them all and normalize the priorities
before dumping.'

def FlushSet(self):

    output.Log('Sorting    and    normalizing    collected    URLs.', 1)
    self._set.sort()
    for url in self._set:
        hash = url.MakeHash()
        dup = self._urls[hash]
        if (dup > 0):
            self._urls[hash] = (-1)
            if (not url.priority):
                url.priority = ('%.4f' % (float(dup) / float(self._dup_max)))
    filename = self._filegen.GeneratePath(self._sitemaps)
    if (not filename):
        output.Fatal("Unexpected:    Couldn't    generate    output    filename.")
    self._sitemaps = (self._sitemaps + 1)
    output.Log(('Writing    Sitemap    file    "%s"    with    %d    URLs' % (filename, len(self._set))), 1)
    frame = None
    file = None
    try:
        if self._filegen.is_gzip:
            basename = os.path.basename(filename)
            frame = open(filename, 'wb')
            file = gzip.GzipFile(fileobj=frame, filename=basename, mode='wt')
        else:
            file = open(filename, 'wt')
        file.write(SITEMAP_HEADER)
        for url in self._set:
            url.WriteXML(file)
        file.write(SITEMAP_FOOTER)
        file.close()
        if frame:
            frame.close()
        frame = None
        file = None
    except IOError:
        output.Fatal(("Couldn't    write    out    to    file:    %s" % filename))
    os.chmod(filename, 420)
    self._set = []
