Skip to content

Commit

Permalink
fix: properly parse idented list
Browse files Browse the repository at this point in the history
  • Loading branch information
zaibon committed Jan 26, 2024
1 parent fa597db commit 1b14731
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions dmidecode/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ def dmidecode_parse(self, buffer): # noqa: C901
break
# Check whether we are inside a \t\t block
if in_block_elemet != "":
in_block_data = self.in_block_re.findall(record_element[1])
in_block_data = self.in_block_re.findall(record_element[i])

if in_block_data:
if not in_block_list:
in_block_list = in_block_data[0][0]
in_block_list = [in_block_data[0]]
else:
in_block_list = in_block_list + "\t\t"
+in_block_data[0][1]
in_block_list.append(in_block_data[0])

data[dmi_handle][in_block_elemet] = in_block_list

continue
else:
# We are out of the \t\t block; reset it again, and let
Expand All @@ -176,7 +176,7 @@ def dmidecode_parse(self, buffer): # noqa: C901
if record_data2:
# This is an array of data - let the loop know we are
# inside an array block
in_block_elemet = record_data2[0][0]
in_block_elemet = record_data2[0]
continue
return data

Expand Down
14 changes: 13 additions & 1 deletion dmidecode/parse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def test_parse(content: str):
"Runtime Size": "96 kB",
"ROM Size": "64 kB",
"BIOS Revision": "1.0",
"Characteristics": [
"BIOS characteristics not supported",
"Targeted content distribution is supported",
],
}
],
1: [
Expand Down Expand Up @@ -52,6 +56,7 @@ def test_parse(content: str):
"Version": "Not Specified",
"Serial Number": "Board-GoogleCloud-8EBFB6FCE14327F972567743E80E23DE",
"Asset Tag": "8EBFB6FC-E143-27F9-7256-7743E80E23DE",
"Features": ["Board is a hosting board"],
"Location In Chassis": "Not Specified",
"Chassis Handle": "0x0099",
"Type": "Motherboard",
Expand Down Expand Up @@ -237,7 +242,14 @@ def test_parse(content: str):
"Partition Row Position": "1",
},
],
32: [{"DMIType": 32, "DMISize": 11, "DMIName": "System Boot Information", "Status": "No errors detected"}],
32: [
{
"DMIType": 32,
"DMISize": 11,
"DMIName": "System Boot Information",
"Status": "No errors detected",
}
],
}
p = DMIParse(content)
for num, exp in expected.items():
Expand Down

0 comments on commit 1b14731

Please sign in to comment.