<commit_before>import _hawkey

Repo = _hawkey.Repo

SYSTEM_REPO_NAME = _hawkey.SYSTEM_REPO_NAME
CMDLINE_REPO_NAME = _hawkey.CMDLINE_REPO_NAME

QUERY_KEYNAME_MAP = {
    'name'    : _hawkey.PKG_NAME,
    'arch'    : _hawkey.PKG_ARCH,
    'summary' : _hawkey.PKG_SUMMARY,
    'file'    : _hawkey.PKG_FILE,
    'repo'    : _hawkey.PKG_REPO,
    'latest'  : _hawkey.PKG_LATEST,
    'upgrades' : _hawkey.PKG_UPGRADES,
    'obsoleting' : _hawkey.PKG_OBSOLETING
}

ICASE = _hawkey.ICASE
QUERY_FT_MAP = {
    'eq' : _hawkey.EQ,
    'gt' : _hawkey.GT,
    'lt' : _hawkey.LT,
    'neq' : _hawkey.NEQ,
    'gte' : _hawkey.EQ | _hawkey.GT,
    'lte' : _hawkey.EQ | _hawkey.LT,
    'substr'  : _hawkey.SUBSTR,
    'glob' : _hawkey.GLOB,
}

Sack = _hawkey.Sack

class Goal(_hawkey.Goal):
    @property
    def problems(self):
        return [self.describe_problem(i) for i in range(0, self.count_problems())]

class Package(_hawkey.Package):
    def evr_eq(self, pkg):
        return self.evr_cmp(pkg) == 0

    def evr_gt(self, pkg):
        return self.evr_cmp(pkg) > 0

    def evr_lt(self, pkg):
        return self.evr_cmp(pkg) < 0

class Query(_hawkey.Query):
    def __init__(self, sack):
        super(Query, self).__init__(sack)
        self.result = None

    def __iter__(self):
        """ Iterate over (cached) query result. """
        return iter(self.run())

    def __getitem__(self, idx):
        return self.run()[idx]

    def _parse_filter_args(self, lst, dct):
        args = []
        filter_flags = 0
        for flag in lst:
            if not flag in [ICASE]:
                raise ValueError("unrecognized flag: %s" % flag)
            filter_flags |= flag
        for (k, match) in dct.items():
            split = k.split("__", 1)
            if len(split) == 1:
                args.append((QUERY_KEYNAME_MAP[split[0]],
                             QUERY_FT_MAP["eq"]|filter_flags,
                             match))
            elif len(split) == 2:
                (keyname, filter_type) = split
                if not keyname in QUERY_KEYNAME_MAP:
                    raise ValueError("Unrecognized key name: %s" % keyname)
                if not filter_type in QUERY_FT_MAP:
                    raise ValueError("Unrecognized filter type: %s" % filter_type)
                args.append((QUERY_KEYNAME_MAP[keyname],
                             QUERY_FT_MAP[filter_type]|filter_flags,<commit_msg>py: Query.__add__()<commit_after>import _hawkey

Repo = _hawkey.Repo

SYSTEM_REPO_NAME = _hawkey.SYSTEM_REPO_NAME
CMDLINE_REPO_NAME = _hawkey.CMDLINE_REPO_NAME

QUERY_KEYNAME_MAP = {
    'name'    : _hawkey.PKG_NAME,
    'arch'    : _hawkey.PKG_ARCH,
    'summary' : _hawkey.PKG_SUMMARY,
    'file'    : _hawkey.PKG_FILE,
    'repo'    : _hawkey.PKG_REPO,
    'latest'  : _hawkey.PKG_LATEST,
    'upgrades' : _hawkey.PKG_UPGRADES,
    'obsoleting' : _hawkey.PKG_OBSOLETING
}

ICASE = _hawkey.ICASE
QUERY_FT_MAP = {
    'eq' : _hawkey.EQ,
    'gt' : _hawkey.GT,
    'lt' : _hawkey.LT,
    'neq' : _hawkey.NEQ,
    'gte' : _hawkey.EQ | _hawkey.GT,
    'lte' : _hawkey.EQ | _hawkey.LT,
    'substr'  : _hawkey.SUBSTR,
    'glob' : _hawkey.GLOB,
}

Sack = _hawkey.Sack

class Goal(_hawkey.Goal):
    @property
    def problems(self):
        return [self.describe_problem(i) for i in range(0, self.count_problems())]

class Package(_hawkey.Package):
    def evr_eq(self, pkg):
        return self.evr_cmp(pkg) == 0

    def evr_gt(self, pkg):
        return self.evr_cmp(pkg) > 0

    def evr_lt(self, pkg):
        return self.evr_cmp(pkg) < 0

class Query(_hawkey.Query):
    def __init__(self, sack):
        super(Query, self).__init__(sack)
        self.result = None

    def __add__(self, operand):
        if not isinstance(operand, list):
            raise TypeError("Only a list can be concatenated to a Query")
        return self.run() + operand

    def __iter__(self):
        """ Iterate over (cached) query result. """
        return iter(self.run())

    def __getitem__(self, idx):
        return self.run()[idx]

    def _parse_filter_args(self, lst, dct):
        args = []
        filter_flags = 0
        for flag in lst:
            if not flag in [ICASE]:
                raise ValueError("unrecognized flag: %s" % flag)
            filter_flags |= flag
        for (k, match) in dct.items():
            split = k.split("__", 1)
            if len(split) == 1:
                args.append((QUERY_KEYNAME_MAP[split[0]],
                             QUERY_FT_MAP["eq"]|filter_flags,
                             match))
            elif len(split) == 2:
                (keyname, filter_type) = split
                if not keyname in QUERY_KEYNAME_MAP:
                    raise ValueError("Unrecognized key name: %s" % keyname)
                if not filter_type in QUERY_FT_MAP:
                    raise ValueError("Unrecognized filter type: %s" % filter_type)
                args.append((QUERY_KEYNAME_MAP[keyname],
                             QUERY_FT_MAP[filter_type]|filter_flags,
{'fraction_non_alphanumeric': 0.11696837079769246, 'fraction_numerical': 0.003580664412174259, 'mean_word_length': 2.1503759398496243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6307517', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1793, 'n_words': 360}