<commit_before>"""Module for inspecting PCI device info"""

from hwinfo.util import CommandParser

class ParserException(Exception):
    pass

class LspciVVParser(CommandParser):
    """Parser object for the output of lspci -vv"""

    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_type>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
        r'Product\ Name:\ (?P<pci_device_vpd_product_name>(.)*)\n',
        r'Subsystem:\ (?P<pci_device_sub_string>(.)*)\n',
    ]

    ITEM_SEPERATOR = "\n\n"

    MUST_HAVE_FIELDS = [
        'pci_device_bus_id',
        'pci_device_type',
        'pci_device_string',
    ]

class LspciNParser(CommandParser):
    """Parser object for the output of lspci -n"""

    #ff:0d.1 0880: 8086:0ee3 (rev 04)
    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_type_id>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
    ]

    ITEM_SEPERATOR = "\n"

    MUST_HAVE_FIELDS = [
        'pci_device_bus_id',
        'pci_device_id',
        'pci_vendor_id',
        'pci_device_type_id',
    ]

class LspciNNMMParser(CommandParser):
    """Parser object for the output of lspci -nnmm"""

    #02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"

    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>[\w+\ \.\-]+)\ \[(?P<pci_device_type_id>[0-9a-fA-F]{4})\]"' \
        + r'\ "(?P<pci_vendor_name>[\w+\ \.\-]+)\ \[(?P<pci_vendor_id>[0-9a-fA-F]{4})\]"\ "(?P<pci_device_name>[\w+\ \.\-]+)\ \[(?P<pci_device_id>[0-9a-fA-F]{4})\]"' \
        + r'\ .*\ "(?P<pci_subvendor_name>[\w+\ \.\-]+)\ \[(?P<pci_subvendor_id>[0-9a-fA-F]{4})\]"\ "(?P<pci_subdevice_name>[\w+\ \.\-]+)\ \[(?P<pci_subdevice_id>[0-9a-fA-F]{4})\]'
    ]

    ITEM_SEPERATOR = "\n"
<commit_msg>Update lspci regex to make the inclusion of subvendor/subdevice references optional.<commit_after>"""Module for inspecting PCI device info"""

from hwinfo.util import CommandParser

class ParserException(Exception):
    pass

class LspciVVParser(CommandParser):
    """Parser object for the output of lspci -vv"""

    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_type>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
        r'Product\ Name:\ (?P<pci_device_vpd_product_name>(.)*)\n',
        r'Subsystem:\ (?P<pci_device_sub_string>(.)*)\n',
    ]

    ITEM_SEPERATOR = "\n\n"

    MUST_HAVE_FIELDS = [
        'pci_device_bus_id',
        'pci_device_type',
        'pci_device_string',
    ]

class LspciNParser(CommandParser):
    """Parser object for the output of lspci -n"""

    #ff:0d.1 0880: 8086:0ee3 (rev 04)
    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_type_id>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
    ]

    ITEM_SEPERATOR = "\n"

    MUST_HAVE_FIELDS = [
        'pci_device_bus_id',
        'pci_device_id',
        'pci_vendor_id',
        'pci_device_type_id',
    ]

class LspciNNMMParser(CommandParser):
    """Parser object for the output of lspci -nnmm"""

    #02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"

    ITEM_REGEXS = [
        r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>[\w+\ \.\-]+)\ \[(?P<pci_device_type_id>[0-9a-fA-F]{4})\]"' \
        + r'\ "(?P<pci_vendor_name>[\w+\ \.\-]+)\ \[(?P<pci_vendor_id>[0-9a-fA-F]{4})\]"\ "(?P<pci_device_name>[\w+\ \.\-]+)\ \[(?P<pci_device_id>[0-9a-fA-F]{4})\]"' \
        + r'\ .*\ "((?P<pci_subvendor_name>[\w+\ \.\-]+)\ \[(?P<pci_subvendor_id>[0-9a-fA-F]{4})\])*"\ "((?P<pci_subdevice_name>[\w+\ \.\-]+)\ \[(?P<pci_subdevice_id>[0-9a-fA-F]{4})\])*',
    ]

    ITEM_SEPERATOR = "\n"

{'fraction_non_alphanumeric': 0.24420896993592903, 'fraction_numerical': 0.046328240512567766, 'mean_word_length': 3.2591815320041975, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '5352877', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1818, 'n_words': 226}