<commit_before># coding: utf-8


#      Copyright (C) 2014 by <NAME><<EMAIL>>
#
#	   This program is free software; you can redistribute it and/or modify
#	   it under the terms of the GNU Lesser General Public License as published by
#	   the Free Software Foundation; either version 2.1 of the License, or
#	   (at your option) any later version.
#
#	   This program is distributed in the hope that it will be useful,
#	   but WITHOUT ANY WARRANTY; without even the implied warranty of
#	   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	   GNU Lesser General Public License for more details.
#
#	   You should have received a copy of the GNU Lesser General Public License
#	   along with this program; if not, see <http://www.gnu.org/licenses/>.

import scsi as SCSI
from scsi_command import SCSICommand

#
# SCSI Inquiry command and definitions
#

#
# INQUIRY VPD pages
#
class VPD:
    '''
    A class to act as a fake enumerator for vital product data page codes
    '''
    SUPPORTED_VPD_PAGES   = 0x00
    DEVICE_IDENTIFICATION = 0x83

class Inquiry(SCSICommand):
    '''
    A class to hold information from a inquiry command to a scsi device
    '''

    def __init__(self, dev, evpd = 0, page_code = 0, alloclen = 96):
        '''
        initialize a new instance

        :param dev: a SCSIDevice instance
        :param evpd: the byte to enable or disable vital product data
        :param page_code: the page code for the vpd page
        :param alloclen: the max number of bytes allocated for the data_in buffer
        '''
        self._evpd = evpd
        self._page_code = page_code
        SCSICommand.__init__(self, dev, 0, alloclen)
        self.cdb = self.build_cdb(evpd, page_code, alloclen)
        self.execute()

    def build_cdb(self, evpd, page_code, alloclen ):
        '''
        method to create a byte array for a Command Descriptor Block with a proper length

        init_cdb returns a byte array of 6,10,12 or 16 bytes depending on the operation code and if
        vital product data is enabled

        :param evpd: the byte to enable or disable vital product data
        :param page_code: the page code for the vpd page
        :param alloclen: the max number of bytes allocated for the data_in buffer
        :return: a byte array representing a code descriptor block
        '''
        cdb = self.init_cdb(SCSI.OPCODE.INQUIRY)
        if (evpd):
            cdb[1] |= 0x01
            cdb[2] = page_code
        cdb[3] = alloclen >> 8
        cdb[4] = alloclen & 0xff
        return cdb

    def unmarshall(self):
        '''
        method to extract relevant data from the byte array that the inquiry command returns

        the content of the result dict depends if vital product data is enabled or not. if vpd is
        enabled we create a list with the received vpd.
        '''
        if self._evpd == 0:
            self.add_result('peripheral_qualifier', self.datain[0] >> 5)
            self.add_result('peripheral_qualifier', self.datain[0] >> 5)
            self.add_result('peripheral_device_type', self.datain[0] & 0x1f)
            self.add_result('version', self.datain[2])
            self.add_result('normaca', self.datain[3] & 0x20)
            self.add_result('hisup', self.datain[3] & 0x10)
            self.add_result('response_data_format', self.datain[3] & 0x0f)
            self.add_result('additional_length', self.datain[4])
            self.add_result('sccs', self.datain[5] & 0x80)
            self.add_result('acc', self.datain[5] & 0x40)
            self.add_result('tpgs', (self.datain[5] >> 4) & 0x03)
            self.add_result('3pc', self.datain[5] & 0x08)
            self.add_result('protect', self.datain[5] & 0x01)
            self.add_result('encserv', self.datain[6] & 0x40)
            self.add_result('vs', self.datain[6] & 0x20)
            self.add_result('multip', self.datain[6] & 0x10)
            self.add_result('addr16', self.datain[6] & 0x01)
            self.add_result('wbus16', self.datain[7] & 0x20)
            self.add_result('sync', self.datain[7] & 0x10)
            self.add_result('cmdque', self.datain[7] & 0x02)
            self.add_result('vs2', self.datain[7] & 0x01)<commit_msg>fixed some code so its more pep8 conform and added some properties<commit_after># coding: utf-8


#      Copyright (C) 2014 by <NAME><<EMAIL>>
#
#	   This program is free software; you can redistribute it and/or modify
#	   it under the terms of the GNU Lesser General Public License as published by
#	   the Free Software Foundation; either version 2.1 of the License, or
#	   (at your option) any later version.
#
#	   This program is distributed in the hope that it will be useful,
#	   but WITHOUT ANY WARRANTY; without even the implied warranty of
#	   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	   GNU Lesser General Public License for more details.
#
#	   You should have received a copy of the GNU Lesser General Public License
#	   along with this program; if not, see <http://www.gnu.org/licenses/>.

from scsi_command import SCSICommand, OPCODE

#
# SCSI Inquiry command and definitions
#

#
# INQUIRY VPD pages
#


class VPD(object):
    """
    A class to act as a fake enumerator for vital product data page codes
    """
    SUPPORTED_VPD_PAGES = 0x00
    DEVICE_IDENTIFICATION = 0x83


class Inquiry(SCSICommand):
    """
    A class to hold information from a inquiry command to a scsi device
    """

    def __init__(self, dev, evpd=0, page_code=0, alloclen=96):
        """
        initialize a new instance

        :param dev: a SCSIDevice instance
        :param evpd: the byte to enable or disable vital product data
        :param page_code: the page code for the vpd page
        :param alloclen: the max number of bytes allocated for the data_in buffer
        """
        self._evpd = evpd
        self._page_code = page_code
        SCSICommand.__init__(self, dev, 0, alloclen)
        self._cdb = self.build_cdb(evpd, page_code, alloclen)
        self.execute()

    @property
    def pagecode(self):
        return self._page_code

    @pagecode.setter
    def pagecode(self, value):
        self._page_code = value

    def build_cdb(self, evpd, page_code, alloclen):
        """
        method to create a byte array for a Command Descriptor Block with a proper length

        init_cdb returns a byte array of 6,10,12 or 16 bytes depending on the operation code and if
        vital product data is enabled

        :param evpd: the byte to enable or disable vital product data
        :param page_code: the page code for the vpd page
        :param alloclen: the max number of bytes allocated for the data_in buffer
        :return: a byte array representing a code descriptor block
        """
        cdb = self.init_cdb(OPCODE.INQUIRY)
        if evpd:
            cdb[1] |= 0x01
            cdb[2] = page_code
        cdb[3] = alloclen >> 8
        cdb[4] = alloclen & 0xff
        return cdb

    def unmarshall(self):
        """
        method to extract relevant data from the byte array that the inquiry command returns

        the content of the result dict depends if vital product data is enabled or not. if vpd is
        enabled we create a list with the received vpd.
        """
        if self._evpd == 0:
            self.add_result('peripheral_qualifier', self.datain[0] >> 5)
            self.add_result('peripheral_qualifier', self.datain[0] >> 5)
            self.add_result('peripheral_device_type', self.datain[0] & 0x1f)
            self.add_result('version', self.datain[2])
            self.add_result('normaca', self.datain[3] & 0x20)
            self.add_result('hisup', self.datain[3] & 0x10)
            self.add_result('response_data_format', self.datain[3] & 0x0f)
            self.add_result('additional_length', self.datain[4])
            self.add_result('sccs', self.datain[5] & 0x80)
            self.add_result('acc', self.datain[5] & 0x40)
            self.add_result('tpgs', (self.datain[5] >> 4) & 0x03)
            self.add_result('3pc', self.datain[5] & 0x08)
            self.add_result('protect', self.datain[5] & 0x01)
            self.add_result('encserv', self.datain[6] & 0x40)
            self.add_result('vs', self.datain[6] & 0x20)
            self.add_result('multip', self.datain[6] & 0x10)
            self.add_result('addr16', self.datain[6] & 0x01)
            self.add_result('wbus16', self.datain[7] & 0x20)
            self.add_result('sync', self.datain[7] & 0x10)
            self.add_result('cmdque', self.datain[7] & 0x02)
            self.add_result('vs2', self.datain[7] & 0x01)
{'fraction_non_alphanumeric': 0.09347422201579192, 'fraction_numerical': 0.0265908035299582, 'mean_word_length': 2.5400739827373613, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4309483', 'n_tokens_mistral': 2800, 'n_tokens_neox': 2653, 'n_words': 877}