<commit_before># Copyright (c) 2015 Yubico AB
# All rights reserved.
#
#   Redistribution and use in source and binary forms, with or
#   without modification, are permitted provided that the following
#   conditions are met:
#
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

__all__ = ['CAPABILITY', 'Mode', 'parse_tlv_list']


class CAPABILITY(object):
    OTP = 0x01
    U2F = 0x02
    CCID = 0x04
    OPGP = 0x08
    PIV = 0x10
    OATH = 0x20


class Mode(object):
    _modes = [  # OTP, U2F, CCID
        (True, False, False),  # 0x00 - OTP
        (False, False, True),  # 0x01 - CCID
        (True, False, True),  # 0x02 - OTP+CCID
        (False, True, False),  # 0x03 - U2F
        (True, True, False),  # 0x04 - OTP+U2F
        (False, True, True),  # 0x05 - U2F+CCID
        (True, True, True)  # 0x06 - OTP+U2F+CCID
    ]

    def __init__(self, otp=False, u2f=False, ccid=False):
        self.otp = bool(otp)
        self.u2f = bool(u2f)
        self.ccid = bool(ccid)
        try:
            self.code = self._modes.index((self.otp, self.u2f, self.ccid))
        except ValueError:
            raise ValueError('Invalid mode!')

    def __str__(self):
        return '+'.join(filter(None, [
            self.otp and 'OTP',
            self.u2f and 'U2F',
            self.ccid and 'CCID'
        ]))

    @classmethod
    def from_code(cls, code):
        code = code & 0b00000111
        return cls(*cls._modes[code])


def parse_tlv_list(data):
    parsed = {}
    while data:
        t, l, data = ord(data[0]), ord(data[1]), data[2:]
        parsed[t], data = data[:l], data[l:]
    return parsed
<commit_msg>Add __eq__ and __ne__ to Mode.<commit_after># Copyright (c) 2015 Yubico AB
# All rights reserved.
#
#   Redistribution and use in source and binary forms, with or
#   without modification, are permitted provided that the following
#   conditions are met:
#
#    1. Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#    2. Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

__all__ = ['CAPABILITY', 'Mode', 'parse_tlv_list']


class CAPABILITY(object):
    OTP = 0x01
    U2F = 0x02
    CCID = 0x04
    OPGP = 0x08
    PIV = 0x10
    OATH = 0x20


class Mode(object):
    _modes = [  # OTP, U2F, CCID
        (True, False, False),  # 0x00 - OTP
        (False, False, True),  # 0x01 - CCID
        (True, False, True),  # 0x02 - OTP+CCID
        (False, True, False),  # 0x03 - U2F
        (True, True, False),  # 0x04 - OTP+U2F
        (False, True, True),  # 0x05 - U2F+CCID
        (True, True, True)  # 0x06 - OTP+U2F+CCID
    ]

    def __init__(self, otp=False, u2f=False, ccid=False):
        self.otp = bool(otp)
        self.u2f = bool(u2f)
        self.ccid = bool(ccid)
        try:
            self.code = self._modes.index((self.otp, self.u2f, self.ccid))
        except ValueError:
            raise ValueError('Invalid mode!')

    def __eq__(self, other):
        return other is not None and self.code == other.code

    def __ne__(self, other):
        return other is None or self.code != other.code

    def __str__(self):
        return '+'.join(filter(None, [
            self.otp and 'OTP',
            self.u2f and 'U2F',
            self.ccid and 'CCID'
        ]))

    @classmethod
    def from_code(cls, code):
        code = code & 0b00000111
        return cls(*cls._modes[code])


def parse_tlv_list(data):
    parsed = {}
    while data:
        t, l, data = ord(data[0]), ord(data[1]), data[2:]
        parsed[t], data = data[:l], data[l:]
    return parsed

{'fraction_non_alphanumeric': 0.09573342736248237, 'fraction_numerical': 0.024330042313117067, 'mean_word_length': 2.7719414893617023, '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': '1145776', 'n_tokens_mistral': 1921, 'n_tokens_neox': 1734, 'n_words': 652}