<commit_before>from __future__ import absolute_import

from bitfield.types import Bit, BitHandler
from django.db.models.lookups import Exact


class BitQueryLookupWrapper(Exact):  # NOQA
    def process_lhs(self, qn, connection, lhs=None):
        lhs_sql, params = super(BitQueryLookupWrapper, self).process_lhs(
            qn, connection, lhs)
        if self.rhs:
            lhs_sql = lhs_sql + ' & %s'
        else:
            lhs_sql = lhs_sql + ' | %s'
        params.extend(self.get_db_prep_lookup(self.rhs, connection)[1])
        return lhs_sql, params

    def get_db_prep_lookup(self, value, connection, prepared=False):
        v = value.mask if isinstance(value, (BitHandler, Bit)) else value
        return super(BitQueryLookupWrapper, self).get_db_prep_lookup(v, connection)

    def get_prep_lookup(self):
        return self.rhs


class BitQuerySaveWrapper(BitQueryLookupWrapper):
    def as_sql(self, qn, connection):
        """
        Create the proper SQL fragment. This inserts something like
        "(T0.flags & value) != 0".

        This will be called by Where.as_sql()
        """
        engine = connection.settings_dict['ENGINE'].rsplit('.', -1)[-1]
        if engine.startswith('postgres'):
            XOR_OPERATOR = '#'
        elif engine.startswith('sqlite'):
            raise NotImplementedError
        else:
            XOR_OPERATOR = '^'

        if self.bit:<commit_msg>query: no `prepared` param for get_db_prep_lookup<commit_after>from __future__ import absolute_import

from bitfield.types import Bit, BitHandler
from django.db.models.lookups import Exact


class BitQueryLookupWrapper(Exact):  # NOQA
    def process_lhs(self, qn, connection, lhs=None):
        lhs_sql, params = super(BitQueryLookupWrapper, self).process_lhs(
            qn, connection, lhs)
        if self.rhs:
            lhs_sql = lhs_sql + ' & %s'
        else:
            lhs_sql = lhs_sql + ' | %s'
        params.extend(self.get_db_prep_lookup(self.rhs, connection)[1])
        return lhs_sql, params

    def get_db_prep_lookup(self, value, connection):
        v = value.mask if isinstance(value, (BitHandler, Bit)) else value
        return super(BitQueryLookupWrapper, self).get_db_prep_lookup(v, connection)

    def get_prep_lookup(self):
        return self.rhs


class BitQuerySaveWrapper(BitQueryLookupWrapper):
    def as_sql(self, qn, connection):
        """
        Create the proper SQL fragment. This inserts something like
        "(T0.flags & value) != 0".

        This will be called by Where.as_sql()
        """
        engine = connection.settings_dict['ENGINE'].rsplit('.', -1)[-1]
        if engine.startswith('postgres'):
            XOR_OPERATOR = '#'
        elif engine.startswith('sqlite'):
            raise NotImplementedError
        else:
            XOR_OPERATOR = '^'

        if self.bit:
{'fraction_non_alphanumeric': 0.1041374474053296, 'fraction_numerical': 0.0035063113604488078, 'mean_word_length': 2.671814671814672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7083663', 'n_tokens_mistral': 893, 'n_tokens_neox': 866, 'n_words': 205}