Check column padding with validation script

This commit is contained in:
Rod Vagg 2021-05-11 14:35:23 +10:00
parent 34df44790f
commit 378abb62f2
No known key found for this signature in database
GPG Key ID: C273792F7D83545D
2 changed files with 23 additions and 7 deletions

View File

@ -93,7 +93,7 @@ p2p-webrtc-star, multiaddr, 0x0113, draft,
p2p-webrtc-direct, multiaddr, 0x0114, draft,
p2p-stardust, multiaddr, 0x0115, draft,
p2p-circuit, multiaddr, 0x0122, permanent,
dag-json, ipld, 0x0129, permanent, MerkleDAG json
dag-json, ipld, 0x0129, permanent, MerkleDAG json
udt, multiaddr, 0x012d, draft,
utp, multiaddr, 0x012e, draft,
unix, multiaddr, 0x0190, permanent,

1 name tag code status description
93 p2p-webrtc-direct multiaddr 0x0114 draft
94 p2p-stardust multiaddr 0x0115 draft
95 p2p-circuit multiaddr 0x0122 permanent
96 dag-json ipld 0x0129 permanent MerkleDAG json
97 udt multiaddr 0x012d draft
98 utp multiaddr 0x012e draft
99 unix multiaddr 0x0190 permanent

View File

@ -20,15 +20,31 @@ def check(fname='table.csv'):
success = True
with open(fname) as table:
tablereader = csv.reader(table, skipinitialspace=True)
tablereader = csv.reader(table, strict=True, skipinitialspace=False)
codes = {}
names = {}
headerOffsets = []
for line, row in enumerate(tablereader):
# Skip the header
if line == 0:
continue
try:
# Check the padding of each column
offset = 0
for col, item in enumerate(row):
le = len(item)
if col == 0: # first column 0 has no padding
offset = le
continue
offset = offset + le
thisOffset = offset - len(item.lstrip())
if line == 0: # header line sets the standard
headerOffsets.append(thisOffset)
elif col < len(headerOffsets) or le != 0:
if thisOffset != headerOffsets[col - 1]:
raise CheckError(f"bad spacing at column {col}")
# Skip the header
if line == 0:
continue
# Check for invalid rows
if len(row) != 5:
raise CheckError(f"expected 4 items, got {len(row)}")
@ -40,7 +56,7 @@ def check(fname='table.csv'):
raise CheckError(f"empty protocol name for code '{code}'")
# Check code format
if not re.match(r"^0x([0-9a-f][0-9a-f])+$", code):
if not re.match(r"^\s*0x([0-9a-f][0-9a-f])+$", code):
raise CheckError(f"code for '{name}' does not look like a byte sequence: '{code}'")
# Check name format