# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer
                wt_faction.pop(int(row['ID']))

        # Heuristic to remove hidden reputations
        def _recurse_rep(faction_id, level=0):
            children = [
                row for row in wt_faction.values()
                if int(row['ParentFactionID']) == faction_id
            ]

            if faction_id != 0:
                rep = wt_faction[faction_id]
                if (
                    # Filters most invalid reputations
                    int(rep['ReputationIndex']) == -1

                    # Filters blacklisted reputations
                    or int(rep['ID']) in IGNORE_FACTION_ID

                    # Filters invalid top-level reputations
                    or (
                        level <= 1 and not int(rep['ReputationFlags[0]']) & 0x8
                    )

                    # Filters most remaining hidden reputations
                    or (
                        not children
                        and int(rep['ReputationFlags[0]']) & 0x4

                        # Exceptions with 0x4 hidden flag set but still
                        # visible.

# Path: dataimporter/tools.py
# def find_or_create_item(L, name, subitems_name=None, error_absent=False):
#     try:
#         return list_find(L, lambda x: x['name'] == name)
#     except StopIteration:
#         if not error_absent:
#             d = {'id': genid(), 'name': name}
#             if subitems_name:
#                 d[subitems_name] = []
#             L.append(d)
#             return d
#         else:
#             raise
# 
# def changelog(*args, **kwargs):
#     print(*args, **kwargs, file=sys.stderr)
# 
# Path: dataimporter/fixer.py
# class WowToolsFixer:
#     """Base class for Wowtools-based data fixers."""
#     load_files = False
# 
#     def __init__(self, *args, build=None):
#         self.build = build
#         self._store_init(*args)
#         if self.load_files:
#             self.wt_files = {
#                 int(e['ID']): e for e in self.wt_get_table('files')
#             }
# 
#     def _store_init(self, *args):
#         raise NotImplementedError
# 
#     def run(self):
#         raise NotImplementedError
# 
#     def wt_get_table(self, table_name):
#         return wowtools.get_table(table_name, self.build)
# 
#     def get_icon_name(self, icon_id: int):
#         assert self.load_files
#         icon_name = str(icon_id)
#         if icon_id in self.wt_files:
#             icon_path = self.wt_files[icon_id]['Path']
#             if 'encrypted' not in icon_path:
#                 icon_name = icon_path.split('/')[-1].rsplit('.', 1)[0].lower()
#                 icon_name = icon_name.replace(' ', '-')
# 
#         return icon_name


# Path: dataimporter/factions.py
from .tools import find_or_create_item, changelog
from .fixer import WowToolsFixer

                wt_faction.pop(int(row['ID']))

        # Heuristic to remove hidden reputations
        def _recurse_rep(faction_id, level=0):
            children = [
                row for row in wt_faction.values()
                if int(row['ParentFactionID']) == faction_id
            ]

            if faction_id != 0:
                rep = wt_faction[faction_id]
                if (
                    # Filters most invalid reputations
                    int(rep['ReputationIndex']) == -1

                    # Filters blacklisted reputations
                    or int(rep['ID']) in IGNORE_FACTION_ID

                    # Filters invalid top-level reputations
                    or (
                        level <= 1 and not int(rep['ReputationFlags[0]']) & 0x8
                    )

                    # Filters most remaining hidden reputations
                    or (
                        not children
                        and int(rep['ReputationFlags[0]']) & 0x4

                        # Exceptions with 0x4 hidden flag set but still
                        # visible.

                        and not int(rep['ReputationFlags[0]']) & 0x2