Ejemplo n.º 1
0
    def _iter_log_names(self):
        dups = set()

        if self._source:
            yield self._source.split('/', 1)[0]
            return

        for well_known in ('Application', 'Security', 'System'):
            dups.add(well_known)
            yield well_known

        key = OpenKeyEx(HKEY_LOCAL_MACHINE,
                        ur'SYSTEM\CurrentControlSet\Services\EventLog', 0,
                        KEY_READ)

        try:
            idx = 0
            while idx < self._max_iters:
                try:
                    source = EnumKey(key, idx)
                    if source in dups:
                        continue

                    dups.add(source)

                    if type(source) == str:
                        source = source.decode(getdefaultencoding())

                    yield source

                except WindowsError:
                    break

                finally:
                    idx += 1

        finally:
            CloseKey(key)