Fix up some python script issues seen with ruff

This commit is contained in:
Martin Mathieson 2024-07-12 15:08:46 +00:00
parent d6f8580675
commit e3e52d8c74
18 changed files with 121 additions and 148 deletions

View File

@ -36,7 +36,6 @@ import re
import argparse import argparse
import time import time
import struct import struct
import array
from threading import Thread from threading import Thread
ERROR_USAGE = 0 ERROR_USAGE = 0

View File

@ -45,7 +45,7 @@ import os
import os.path import os.path
import time import time
import getopt import getopt
import traceback #import traceback
try: try:
from ply import lex from ply import lex
@ -645,9 +645,9 @@ class EthCtx:
return False return False
def value_max(self, a, b): def value_max(self, a, b):
if (a == 'MAX') or (b == 'MAX'): return 'MAX'; if (a == 'MAX') or (b == 'MAX'): return 'MAX'
if a == 'MIN': return b; if a == 'MIN': return b
if b == 'MIN': return a; if b == 'MIN': return a
try: try:
if (int(a) > int(b)): if (int(a) > int(b)):
return a return a
@ -658,9 +658,9 @@ class EthCtx:
return "MAX((%s),(%s))" % (a, b) return "MAX((%s),(%s))" % (a, b)
def value_min(self, a, b): def value_min(self, a, b):
if (a == 'MIN') or (b == 'MIN'): return 'MIN'; if (a == 'MIN') or (b == 'MIN'): return 'MIN'
if a == 'MAX': return b; if a == 'MAX': return b
if b == 'MAX': return a; if b == 'MAX': return a
try: try:
if (int(a) < int(b)): if (int(a) < int(b)):
return a return a
@ -724,7 +724,7 @@ class EthCtx:
val = self.type[t]['val'] val = self.type[t]['val']
(ftype, display) = val.eth_ftype(self) (ftype, display) = val.eth_ftype(self)
attr.update({ 'TYPE' : ftype, 'DISPLAY' : display, attr.update({ 'TYPE' : ftype, 'DISPLAY' : display,
'STRINGS' : val.eth_strings(), 'BITMASK' : '0' }); 'STRINGS' : val.eth_strings(), 'BITMASK' : '0' })
else: else:
attr.update(self.type[t]['attr']) attr.update(self.type[t]['attr'])
attr.update(self.eth_type[self.type[t]['ethname']]['attr']) attr.update(self.eth_type[self.type[t]['ethname']]['attr'])
@ -1061,7 +1061,7 @@ class EthCtx:
#--- eth_clean -------------------------------------------------------------- #--- eth_clean --------------------------------------------------------------
def eth_clean(self): def eth_clean(self):
self.proto = self.proto_opt; self.proto = self.proto_opt
#--- ASN.1 tables ---------------- #--- ASN.1 tables ----------------
self.assign = {} self.assign = {}
self.assign_ord = [] self.assign_ord = []
@ -1243,14 +1243,12 @@ class EthCtx:
for t in self.eth_type_ord: for t in self.eth_type_ord:
bits = self.eth_type[t]['val'].eth_named_bits() bits = self.eth_type[t]['val'].eth_named_bits()
if (bits): if (bits):
old_val = 0
for (val, id) in bits: for (val, id) in bits:
self.named_bit.append({'name' : id, 'val' : val, self.named_bit.append({'name' : id, 'val' : val,
'ethname' : 'hf_%s_%s_%s' % (self.eproto, t, asn2c(id)), 'ethname' : 'hf_%s_%s_%s' % (self.eproto, t, asn2c(id)),
'ftype' : 'FT_BOOLEAN', 'display' : '8', 'ftype' : 'FT_BOOLEAN', 'display' : '8',
'strings' : 'NULL', 'strings' : 'NULL',
'bitmask' : '0x'+('80','40','20','10','08','04','02','01')[val%8]}) 'bitmask' : '0x'+('80','40','20','10','08','04','02','01')[val%8]})
old_val = val + 1
if self.eth_type[t]['val'].eth_need_tree(): if self.eth_type[t]['val'].eth_need_tree():
self.eth_type[t]['tree'] = "ett_%s_%s" % (self.eth_type[t]['proto'], t) self.eth_type[t]['tree'] = "ett_%s_%s" % (self.eth_type[t]['proto'], t)
else: else:
@ -1614,7 +1612,7 @@ class EthCtx:
#--- eth_out_pdu_decl ---------------------------------------------------------- #--- eth_out_pdu_decl ----------------------------------------------------------
def eth_out_pdu_decl(self, f): def eth_out_pdu_decl(self, f):
t = self.eth_hf[f]['ethtype'] #t = self.eth_hf[f]['ethtype']
out = '' out = ''
if (not self.eth_hf[f]['pdu']['export']): if (not self.eth_hf[f]['pdu']['export']):
out += 'static ' out += 'static '
@ -1994,7 +1992,7 @@ class EthCtx:
if first_decl: if first_decl:
fx.write(' /*--- Syntax registrations ---*/\n') fx.write(' /*--- Syntax registrations ---*/\n')
first_decl = False first_decl = False
fx.write(' %sregister_ber_syntax_dissector(%s, proto_%s, dissect_%s_PDU);\n' % (new_prefix, k, self.eproto, reg['pdu'])); fx.write(' %sregister_ber_syntax_dissector(%s, proto_%s, dissect_%s_PDU);\n' % (new_prefix, k, self.eproto, reg['pdu']))
fempty=False fempty=False
self.output.file_close(fx, discard=fempty) self.output.file_close(fx, discard=fempty)
@ -2338,13 +2336,13 @@ class EthCnf:
return name in self.fn and self.fn[name]['FN_BODY'] return name in self.fn and self.fn[name]['FN_BODY']
def get_fn_text(self, name, ctx): def get_fn_text(self, name, ctx):
if (name not in self.fn): if (name not in self.fn):
return ''; return ''
if (not self.fn[name][ctx]): if (not self.fn[name][ctx]):
return ''; return ''
self.fn[name][ctx]['used'] = True self.fn[name][ctx]['used'] = True
out = self.fn[name][ctx]['text'] out = self.fn[name][ctx]['text']
if (not self.suppress_line): if (not self.suppress_line):
out = '#line %u "%s"\n%s\n' % (self.fn[name][ctx]['lineno'], rel_dissector_path(self.fn[name][ctx]['fn']), out); out = '#line %u "%s"\n%s\n' % (self.fn[name][ctx]['lineno'], rel_dissector_path(self.fn[name][ctx]['fn']), out)
return out return out
def add_pdu(self, par, fn, lineno): def add_pdu(self, par, fn, lineno):
@ -2966,7 +2964,7 @@ class EthOut:
#--- output_fname ------------------------------------------------------- #--- output_fname -------------------------------------------------------
def output_fname(self, ftype, ext='c'): def output_fname(self, ftype, ext='c'):
fn = '' fn = ''
if not ext in ('cnf',): if ext not in ('cnf',):
fn += 'packet-' fn += 'packet-'
fn += self.outnm fn += self.outnm
if (ftype): if (ftype):
@ -3063,10 +3061,10 @@ class EthOut:
include = re.compile(r'^\s*#\s*include\s+[<"](?P<fname>[^>"]+)[>"]', re.IGNORECASE) include = re.compile(r'^\s*#\s*include\s+[<"](?P<fname>[^>"]+)[>"]', re.IGNORECASE)
cont_linenum = 0; cont_linenum = 0
while (True): while (True):
cont_linenum = cont_linenum + 1; cont_linenum = cont_linenum + 1
line = fin.readline() line = fin.readline()
if (line == ''): break if (line == ''): break
ifile = None ifile = None
@ -3748,9 +3746,9 @@ class Module (Node):
class Module_Body (Node): class Module_Body (Node):
def to_python (self, ctx): def to_python (self, ctx):
# XXX handle exports, imports. # XXX handle exports, imports.
l = [x.to_python (ctx) for x in self.assign_list] list = [x.to_python (ctx) for x in self.assign_list]
l = [a for a in l if a != ''] list = [a for a in list if a != '']
return "\n".join (l) return "\n".join(list)
def to_eth(self, ectx): def to_eth(self, ectx):
# Exports # Exports
@ -4093,7 +4091,8 @@ class SeqType (SqType):
autotag = True autotag = True
lst = self.all_components() lst = self.all_components()
for e in (self.elt_list): for e in (self.elt_list):
if e.val.HasOwnTag(): autotag = False; break; if e.val.HasOwnTag(): autotag = False
break
# expand COMPONENTS OF # expand COMPONENTS OF
if self.need_components(): if self.need_components():
if components_available: if components_available:
@ -4113,7 +4112,7 @@ class SeqType (SqType):
e.val.SetName("eag_v%s" % (e.val.ver)) e.val.SetName("eag_v%s" % (e.val.ver))
else: else:
e.val.SetName("eag_%d" % (eag_num)) e.val.SetName("eag_%d" % (eag_num))
eag_num += 1; eag_num += 1
else: # expand else: # expand
new_ext_list = [] new_ext_list = []
for e in (self.ext_list): for e in (self.ext_list):
@ -4498,10 +4497,10 @@ class ChoiceType (Type):
if (ectx.NeedTags() and (ectx.tag_def == 'AUTOMATIC')): if (ectx.NeedTags() and (ectx.tag_def == 'AUTOMATIC')):
autotag = True autotag = True
for e in (self.elt_list): for e in (self.elt_list):
if e.HasOwnTag(): autotag = False; break; if e.HasOwnTag(): autotag = False; break
if autotag and hasattr(self, 'ext_list'): if autotag and hasattr(self, 'ext_list'):
for e in (self.ext_list): for e in (self.ext_list):
if e.HasOwnTag(): autotag = False; break; if e.HasOwnTag(): autotag = False; break
# do autotag # do autotag
if autotag: if autotag:
atag = 0 atag = 0
@ -5613,7 +5612,7 @@ class BitStringType (Type):
if (self.named_list): if (self.named_list):
sorted_list = self.named_list sorted_list = self.named_list
sorted_list.sort() sorted_list.sort()
expected_bit_no = 0; expected_bit_no = 0
for e in (sorted_list): for e in (sorted_list):
# Fill the table with "spare_bit" for "un named bits" # Fill the table with "spare_bit" for "un named bits"
if (int(e.val) != 0) and (expected_bit_no != int(e.val)): if (int(e.val) != 0) and (expected_bit_no != int(e.val)):
@ -7350,7 +7349,7 @@ def p_cls_syntax_4 (t):
def p_cls_syntax_5 (t): def p_cls_syntax_5 (t):
'cls_syntax : CODE Value' 'cls_syntax : CODE Value'
fld = get_class_field(t[1]); fld = get_class_field(t[1])
t[0] = { fld : t[2] } t[0] = { fld : t[2] }
if isinstance(t[2], ChoiceValue): if isinstance(t[2], ChoiceValue):
fldt = fld + '.' + t[2].choice fldt = fld + '.' + t[2].choice
@ -8074,7 +8073,7 @@ def asn2wrs_main():
global quiet global quiet
try: try:
opts, args = getopt.getopt(sys.argv[1:], "h?d:D:buXp:qFTo:O:c:I:eESs:kLCr:"); opts, args = getopt.getopt(sys.argv[1:], "h?d:D:buXp:qFTo:O:c:I:eESs:kLCr:")
except getopt.GetoptError: except getopt.GetoptError:
eth_usage(); sys.exit(2) eth_usage(); sys.exit(2)
if len(args) < 1: if len(args) < 1:
@ -8097,10 +8096,10 @@ def asn2wrs_main():
ectx.merge_modules = False ectx.merge_modules = False
ectx.group_by_prot = False ectx.group_by_prot = False
ectx.conform.last_group = 0 ectx.conform.last_group = 0
ectx.conform.suppress_line = False; ectx.conform.suppress_line = False
ectx.output.outnm = None ectx.output.outnm = None
ectx.output.single_file = None ectx.output.single_file = None
ectx.constraints_check = False; ectx.constraints_check = False
for o, a in opts: for o, a in opts:
if o in ("-h", "-?"): if o in ("-h", "-?"):
eth_usage(); sys.exit(2) eth_usage(); sys.exit(2)
@ -8138,7 +8137,7 @@ def asn2wrs_main():
if a: par.append(a) if a: par.append(a)
ectx.conform.set_opt(o, par, "commandline", 0) ectx.conform.set_opt(o, par, "commandline", 0)
(ld, yd, pd) = (0, 0, 0); (ld, yd, pd) = (0, 0, 0)
if ectx.dbg('l'): ld = 1 if ectx.dbg('l'): ld = 1
if ectx.dbg('y'): yd = 1 if ectx.dbg('y'): yd = 1
if ectx.dbg('p'): pd = 2 if ectx.dbg('p'): pd = 2

View File

@ -191,8 +191,8 @@ async def check_all_links(links):
except (asyncio.CancelledError): except (asyncio.CancelledError):
await session.close() await session.close()
for l in links: for link in links:
l.validate() link.validate()
################################################################# #################################################################
@ -288,21 +288,21 @@ asyncio.run(check_all_links(links))
if os.path.exists('failures.txt'): if os.path.exists('failures.txt'):
shutil.copyfile('failures.txt', 'failures_last_run.txt') shutil.copyfile('failures.txt', 'failures_last_run.txt')
with open('failures.txt', 'w') as f_f: with open('failures.txt', 'w') as f_f:
for l in links: for link in links:
if l.tested and not l.success: if link.tested and not link.success:
f_f.write(str(l) + '\n') f_f.write(str(link) + '\n')
# And successes # And successes
with open('successes.txt', 'w') as f_s: with open('successes.txt', 'w') as f_s:
for l in links: for link in links:
if l.tested and l.success: if link.tested and link.success:
f_s.write(str(l) + '\n') f_s.write(str(link) + '\n')
# Count and show overall stats. # Count and show overall stats.
passed, failed = 0, 0 passed, failed = 0, 0
for l in links: for link in links:
if l.tested: if link.tested:
if l.success: if link.success:
passed += 1 passed += 1
else: else:
failed += 1 failed += 1

View File

@ -12,8 +12,9 @@ import subprocess
import argparse import argparse
import signal import signal
import glob import glob
from collections import Counter
from spellchecker import SpellChecker
from collections import Counter
from html.parser import HTMLParser from html.parser import HTMLParser
import urllib.request import urllib.request
@ -51,7 +52,6 @@ signal.signal(signal.SIGINT, signal_handler)
# Create spellchecker, and augment with some Wireshark words. # Create spellchecker, and augment with some Wireshark words.
from spellchecker import SpellChecker
# Set up our dict with words from text file. # Set up our dict with words from text file.
spell = SpellChecker() spell = SpellChecker()
spell.word_frequency.load_text_file('./tools/wireshark_words.txt') spell.word_frequency.load_text_file('./tools/wireshark_words.txt')
@ -499,7 +499,7 @@ if not args.no_wikipedia:
parser.feed(content) parser.feed(content)
content = parser.content.strip() content = parser.content.strip()
wiki_db = dict(l.lower().split('->', maxsplit=1) for l in content.splitlines()) wiki_db = dict(line.lower().split('->', maxsplit=1) for line in content.splitlines())
del wiki_db['cmo'] # All false positives. del wiki_db['cmo'] # All false positives.
del wiki_db['ect'] # Too many false positives. del wiki_db['ect'] # Too many false positives.
del wiki_db['thru'] # We'll let that one thru. ;-) del wiki_db['thru'] # We'll let that one thru. ;-)
@ -514,11 +514,11 @@ if not args.no_wikipedia:
spell.word_frequency.remove_words([word]) spell.word_frequency.remove_words([word])
#print('Removed', word) #print('Removed', word)
removed += 1 removed += 1
except: except Exception:
pass pass
print('Removed', removed, 'known bad words') print('Removed', removed, 'known bad words')
except: except Exception:
print('Failed to fetch and/or parse Wikipedia mispellings!') print('Failed to fetch and/or parse Wikipedia mispellings!')
@ -555,7 +555,7 @@ if args.open:
# Filter files. # Filter files.
files_staged = list(filter(lambda f : isAppropriateFile(f) and not isGeneratedFile(f), files_staged)) files_staged = list(filter(lambda f : isAppropriateFile(f) and not isGeneratedFile(f), files_staged))
for f in files_staged: for f in files_staged:
if not f in files: if f not in files:
files.append(f) files.append(f)
if args.glob: if args.glob:

View File

@ -61,14 +61,14 @@ class CalledSymbols:
# Run command to check symbols. # Run command to check symbols.
command = ['nm', object_file] command = ['nm', object_file]
for f in subprocess.check_output(command).splitlines(): for f in subprocess.check_output(command).splitlines():
l = str(f)[2:-1] line = str(f)[2:-1]
# Lines might, or might not, have an address before letter and symbol. # Lines might, or might not, have an address before letter and symbol.
p1 = re.compile(r'[0-9a-f]* ([a-zA-Z]) (.*)') p1 = re.compile(r'[0-9a-f]* ([a-zA-Z]) (.*)')
p2 = re.compile(r'[ ]* ([a-zA-Z]) (.*)') p2 = re.compile(r'[ ]* ([a-zA-Z]) (.*)')
m = p1.match(l) m = p1.match(line)
if not m: if not m:
m = p2.match(l) m = p2.match(line)
if m: if m:
letter = m.group(1) letter = m.group(1)
function_name = m.group(2) function_name = m.group(2)
@ -113,15 +113,15 @@ class DefinedSymbols:
command = ['nm', object_file] command = ['nm', object_file]
for f in subprocess.check_output(command).splitlines(): for f in subprocess.check_output(command).splitlines():
# Line consists of whitespace, [address], letter, symbolName # Line consists of whitespace, [address], letter, symbolName
l = str(f)[2:-1] line = str(f)[2:-1]
p = re.compile(r'[0-9a-f]* ([a-zA-Z]) (.*)') p = re.compile(r'[0-9a-f]* ([a-zA-Z]) (.*)')
m = p.match(l) m = p.match(line)
if m: if m:
letter = m.group(1) letter = m.group(1)
function_name = m.group(2) function_name = m.group(2)
# Globally-defined symbols. Would be 't' or 'd' if already static.. # Globally-defined symbols. Would be 't' or 'd' if already static..
if letter in 'TD': if letter in 'TD':
self.addDefinedSymbol(function_name, l) self.addDefinedSymbol(function_name, line)
def addDefinedSymbol(self, symbol, line): def addDefinedSymbol(self, symbol, line):
self.global_symbols[symbol] = line self.global_symbols[symbol] = line
@ -156,7 +156,7 @@ class DefinedSymbols:
def checkIfSymbolsAreCalled(self, called_symbols): def checkIfSymbolsAreCalled(self, called_symbols):
global issues_found global issues_found
for f in self.global_symbols: for f in self.global_symbols:
if not f in called_symbols: if f not in called_symbols:
mentioned_in_header = self.mentionedInHeaders(f) mentioned_in_header = self.mentionedInHeaders(f)
fun = self.global_symbols[f] fun = self.global_symbols[f]
print(self.filename, '' if not self.from_generated_file else '(GENERATED)', print(self.filename, '' if not self.from_generated_file else '(GENERATED)',
@ -299,7 +299,7 @@ elif args.open:
for f in files: for f in files:
files.append(f) files.append(f)
for f in files_staged: for f in files_staged:
if not f in files: if f not in files:
files.append(f) files.append(f)
else: else:
# Find all dissector files from folder. # Find all dissector files from folder.

View File

@ -209,16 +209,10 @@ class Item:
if self.check_bit(self.mask_value, n): if self.check_bit(self.mask_value, n):
self.bits_set += 1 self.bits_set += 1
def check_bit(self, value, n):
return (value & (0x1 << n)) != 0
def __str__(self): def __str__(self):
return 'Item ({0} "{1}" {2} type={3}:{4} strings={5} mask={6})'.format(self.filename, self.label, self.filter, return 'Item ({0} "{1}" {2} type={3}:{4} strings={5} mask={6})'.format(self.filename, self.label, self.filter,
self.item_type, self.type_modifier, self.strings, self.mask) self.item_type, self.type_modifier, self.strings, self.mask)
def set_mask_value(self, macros): def set_mask_value(self, macros):
try: try:
self.mask_read = True self.mask_read = True
@ -226,12 +220,11 @@ class Item:
# Substitute mask if found as a macro.. # Substitute mask if found as a macro..
if self.mask in macros: if self.mask in macros:
self.mask = macros[self.mask] self.mask = macros[self.mask]
elif any(not c in '0123456789abcdefABCDEFxX' for c in self.mask): elif any(c not in '0123456789abcdefABCDEFxX' for c in self.mask):
self.mask_read = False self.mask_read = False
self.mask_value = 0 self.mask_value = 0
return return
# Read according to the appropriate base. # Read according to the appropriate base.
if self.mask.startswith('0x'): if self.mask.startswith('0x'):
self.mask_value = int(self.mask, 16) self.mask_value = int(self.mask, 16)
@ -239,7 +232,7 @@ class Item:
self.mask_value = int(self.mask, 8) self.mask_value = int(self.mask, 8)
else: else:
self.mask_value = int(self.mask, 10) self.mask_value = int(self.mask, 10)
except: except Exception:
self.mask_read = False self.mask_read = False
self.mask_value = 0 self.mask_value = 0
@ -261,8 +254,7 @@ class Item:
try: try:
# For FT_BOOLEAN, modifier is just numerical number of bits. Round up to next nibble. # For FT_BOOLEAN, modifier is just numerical number of bits. Round up to next nibble.
return int((int(self.type_modifier) + 3)/4)*4 return int((int(self.type_modifier) + 3)/4)*4
except: except Exception:
#print('oops', self)
return 0 return 0
else: else:
if self.item_type in field_widths: if self.item_type in field_widths:
@ -332,7 +324,6 @@ def findValueStrings(filename):
# Look for hf items (i.e. full item to be registered) in a dissector file. # Look for hf items (i.e. full item to be registered) in a dissector file.
def find_items(filename, macros, check_mask=False, mask_exact_width=False, check_label=False, check_consecutive=False): def find_items(filename, macros, check_mask=False, mask_exact_width=False, check_label=False, check_consecutive=False):
is_generated = isGeneratedFile(filename)
items = {} items = {}
with open(filename, 'r', encoding="utf8", errors="ignore") as f: with open(filename, 'r', encoding="utf8", errors="ignore") as f:
contents = f.read() contents = f.read()
@ -501,7 +492,7 @@ def checkFile(filename, common_tfs, look_for_common=False, check_value_strings=F
for c in common_tfs: for c in common_tfs:
m = re.search(r'TFS\(\s*\&' + c + r'\s*\)', contents) m = re.search(r'TFS\(\s*\&' + c + r'\s*\)', contents)
if m: if m:
if not c in common_usage: if c not in common_usage:
common_usage[c] = 1 common_usage[c] = 1
else: else:
common_usage[c] += 1 common_usage[c] += 1

View File

@ -47,12 +47,12 @@ class Call:
if length: if length:
try: try:
self.length = int(length) self.length = int(length)
except: except Exception:
if length.isupper(): if length.isupper():
if length in macros: if length in macros:
try: try:
self.length = int(macros[length]) self.length = int(macros[length])
except: except Exception:
pass pass
pass pass
@ -148,7 +148,6 @@ class APICheck:
length = m.group(3) length = m.group(3)
# Add call. We have length if re had 3 groups. # Add call. We have length if re had 3 groups.
num_groups = self.p.groups
self.calls.append(Call(m.group(2), self.calls.append(Call(m.group(2),
macros, macros,
line_number=line_number, line_number=line_number,
@ -163,7 +162,6 @@ class APICheck:
# Walk past any l.s. 0 bits in value # Walk past any l.s. 0 bits in value
n = 0 n = 0
mask_start = n
# Walk through any bits that are set and check they are in mask # Walk through any bits that are set and check they are in mask
while self.check_bit(value, n) and n <= 63: while self.check_bit(value, n) and n <= 63:
if not self.check_bit(mask, n): if not self.check_bit(mask, n):
@ -191,7 +189,7 @@ class APICheck:
warnings_found += 1 warnings_found += 1
# Needs a +ve length # Needs a +ve length
if self.positive_length and call.length != None: if self.positive_length and call.length is not None:
if call.length != -1 and call.length <= 0: if call.length != -1 and call.length <= 0:
print('Error: ' + self.fun_name + '(.., ' + call.hf_name + ', ...) called at ' + print('Error: ' + self.fun_name + '(.., ' + call.hf_name + ', ...) called at ' +
self.file + ':' + str(call.line_number) + self.file + ':' + str(call.line_number) +
@ -200,7 +198,7 @@ class APICheck:
if call.hf_name in items_defined: if call.hf_name in items_defined:
# Is type allowed? # Is type allowed?
if not items_defined[call.hf_name].item_type in self.allowed_types: if items_defined[call.hf_name].item_type not in self.allowed_types:
print('Error: ' + self.fun_name + '(.., ' + call.hf_name + ', ...) called at ' + print('Error: ' + self.fun_name + '(.., ' + call.hf_name + ', ...) called at ' +
self.file + ':' + str(call.line_number) + self.file + ':' + str(call.line_number) +
' with type ' + items_defined[call.hf_name].item_type) ' with type ' + items_defined[call.hf_name].item_type)
@ -226,7 +224,7 @@ class APICheck:
warnings_found += 1 warnings_found += 1
if check_missing_items: if check_missing_items:
if call.hf_name in items_declared and not call.hf_name in items_defined and not call.hf_name in items_declared_extern: if call.hf_name in items_declared and call.hf_name not in items_defined and call.hf_name not in items_declared_extern:
#not in common_hf_var_names: #not in common_hf_var_names:
print('Warning:', self.file + ':' + str(call.line_number), print('Warning:', self.file + ':' + str(call.line_number),
self.fun_name + ' called for "' + call.hf_name + '"', ' - but no item found') self.fun_name + ' called for "' + call.hf_name + '"', ' - but no item found')
@ -284,7 +282,7 @@ class ProtoTreeAddItemCheck(APICheck):
enc = m.group(3) enc = m.group(3)
hf_name = m.group(1) hf_name = m.group(1)
if not enc.startswith('ENC_'): if not enc.startswith('ENC_'):
if not enc in { 'encoding', 'enc', 'client_is_le', 'cigi_byte_order', 'endian', 'endianess', 'machine_encoding', 'byte_order', 'bLittleEndian', if enc not in { 'encoding', 'enc', 'client_is_le', 'cigi_byte_order', 'endian', 'endianess', 'machine_encoding', 'byte_order', 'bLittleEndian',
'p_mq_parm->mq_str_enc', 'p_mq_parm->mq_int_enc', 'p_mq_parm->mq_str_enc', 'p_mq_parm->mq_int_enc',
'iEnc', 'strid_enc', 'iCod', 'nl_data->encoding', 'iEnc', 'strid_enc', 'iCod', 'nl_data->encoding',
'argp->info->encoding', 'gquic_info->encoding', 'writer_encoding', 'argp->info->encoding', 'gquic_info->encoding', 'writer_encoding',
@ -343,7 +341,7 @@ class ProtoTreeAddItemCheck(APICheck):
'item type is', items_defined[call.hf_name].item_type, 'but call has len', call.length) 'item type is', items_defined[call.hf_name].item_type, 'but call has len', call.length)
warnings_found += 1 warnings_found += 1
elif check_missing_items: elif check_missing_items:
if call.hf_name in items_declared and not call.hf_name in items_declared_extern: if call.hf_name in items_declared and call.hf_name not in items_declared_extern:
#not in common_hf_var_names: #not in common_hf_var_names:
print('Warning:', self.file + ':' + str(call.line_number), print('Warning:', self.file + ':' + str(call.line_number),
self.fun_name + ' called for "' + call.hf_name + '"', ' - but no item found') self.fun_name + ' called for "' + call.hf_name + '"', ' - but no item found')
@ -570,7 +568,7 @@ class ValueString:
value,label = m.group(1), m.group(2) value,label = m.group(1), m.group(2)
if value in macros: if value in macros:
value = macros[value] value = macros[value]
elif any(not c in '0123456789abcdefABCDEFxX' for c in value): elif any(c not in '0123456789abcdefABCDEFxX' for c in value):
self.valid = False self.valid = False
return return
@ -584,7 +582,7 @@ class ValueString:
value = int(value, 8) value = int(value, 8)
else: else:
value = int(value, 10) value = int(value, 10)
except: except Exception:
return return
global warnings_found global warnings_found
@ -634,7 +632,7 @@ class ValueString:
span = self.max_value - self.min_value + 1 span = self.max_value - self.min_value + 1
if num_items > 4 and span > num_items and (span-num_items <=1): if num_items > 4 and span > num_items and (span-num_items <=1):
for val in range(self.min_value, self.max_value): for val in range(self.min_value, self.max_value):
if not val in self.parsed_vals: if val not in self.parsed_vals:
print('Warning:', self.file, ': value_string', self.name, '- value', val, 'missing?', '(', num_items, 'entries)') print('Warning:', self.file, ': value_string', self.name, '- value', val, 'missing?', '(', num_items, 'entries)')
global warnings_found global warnings_found
warnings_found += 1 warnings_found += 1
@ -652,7 +650,7 @@ class ValueString:
# Be forgiving about first or last entry # Be forgiving about first or last entry
first_val = list(self.parsed_vals)[0] first_val = list(self.parsed_vals)[0]
last_val = list(self.parsed_vals)[-1] last_val = list(self.parsed_vals)[-1]
if not first_val in matching_label_entries or not last_val in matching_label_entries: if first_val not in matching_label_entries or last_val not in matching_label_entries:
return return
print('Warning:', self.file, ': value_string', self.name, 'Labels match value except for 1!', matching_label_entries, num_items, self) print('Warning:', self.file, ': value_string', self.name, 'Labels match value except for 1!', matching_label_entries, num_items, self)
@ -710,12 +708,12 @@ class RangeString:
min,max,label = m.group(1), m.group(2), m.group(3) min,max,label = m.group(1), m.group(2), m.group(3)
if min in macros: if min in macros:
min = macros[min] min = macros[min]
elif any(not c in '0123456789abcdefABCDEFxX' for c in min): elif any(c not in '0123456789abcdefABCDEFxX' for c in min):
self.valid = False self.valid = False
return return
if max in macros: if max in macros:
max = macros[max] max = macros[max]
elif any(not c in '0123456789abcdefABCDEFxX' for c in max): elif any(c not in '0123456789abcdefABCDEFxX' for c in max):
self.valid = False self.valid = False
return return
@ -738,7 +736,7 @@ class RangeString:
max = int(max, 8) max = int(max, 8)
else: else:
max = int(max, 10) max = int(max, 10)
except: except Exception:
return return
# Now check what we've found. # Now check what we've found.
@ -958,7 +956,7 @@ class Item:
# Optionally check that mask bits are contiguous # Optionally check that mask bits are contiguous
if check_mask: if check_mask:
if self.mask_read and not mask in { 'NULL', '0x0', '0', '0x00' }: if self.mask_read and mask not in { 'NULL', '0x0', '0', '0x00' }:
self.check_contiguous_bits(mask) self.check_contiguous_bits(mask)
self.check_num_digits(self.mask) self.check_num_digits(self.mask)
# N.B., if last entry in set is removed, see around 18,000 warnings # N.B., if last entry in set is removed, see around 18,000 warnings
@ -1063,7 +1061,7 @@ class Item:
# Substitute mask if found as a macro.. # Substitute mask if found as a macro..
if self.mask in macros: if self.mask in macros:
self.mask = macros[self.mask] self.mask = macros[self.mask]
elif any(not c in '0123456789abcdefABCDEFxX' for c in self.mask): elif any(c not in '0123456789abcdefABCDEFxX' for c in self.mask):
self.mask_read = False self.mask_read = False
self.mask_value = 0 self.mask_value = 0
#print(self.filename, 'Could not read:', '"' + self.mask + '"') #print(self.filename, 'Could not read:', '"' + self.mask + '"')
@ -1076,7 +1074,7 @@ class Item:
self.mask_value = int(self.mask, 8) self.mask_value = int(self.mask, 8)
else: else:
self.mask_value = int(self.mask, 10) self.mask_value = int(self.mask, 10)
except: except Exception:
self.mask_read = False self.mask_read = False
self.mask_value = 0 self.mask_value = 0
@ -1092,7 +1090,7 @@ class Item:
# Substitute display if found as a macro.. # Substitute display if found as a macro..
if display in macros: if display in macros:
display = macros[display] display = macros[display]
elif any(not c in '0123456789abcdefABCDEFxX' for c in display): elif any(c not in '0123456789abcdefABCDEFxX' for c in display):
self.display_read = False self.display_read = False
self.display_value = 0 self.display_value = 0
return return
@ -1104,7 +1102,7 @@ class Item:
self.display_value = int(display, 8) self.display_value = int(display, 8)
else: else:
self.display_value = int(display, 10) self.display_value = int(display, 10)
except: except Exception:
self.display_read = False self.display_read = False
self.display_value = 0 self.display_value = 0
@ -1195,7 +1193,7 @@ class Item:
# Look up the field width # Look up the field width
field_width = 0 field_width = 0
if not self.item_type in field_widths: if self.item_type not in field_widths:
print('unexpected item_type is ', self.item_type) print('unexpected item_type is ', self.item_type)
field_width = 64 field_width = 64
else: else:
@ -1233,7 +1231,7 @@ class Item:
try: try:
# For FT_BOOLEAN, modifier is just numerical number of bits. Round up to next nibble. # For FT_BOOLEAN, modifier is just numerical number of bits. Round up to next nibble.
return int((int(self.display) + 3)/4)*4 return int((int(self.display) + 3)/4)*4
except: except Exception:
return None return None
else: else:
if self.item_type in field_widths: if self.item_type in field_widths:
@ -1323,13 +1321,11 @@ class Item:
def check_mask_if_in_field_array(self, mask, field_arrays): def check_mask_if_in_field_array(self, mask, field_arrays):
# Work out if this item appears in a field array # Work out if this item appears in a field array
found = False found = False
array_name = None
for arr in field_arrays: for arr in field_arrays:
list = field_arrays[arr][0] list = field_arrays[arr][0]
if self.hf in list: if self.hf in list:
# These need to have a mask - don't judge for being 0 # These need to have a mask - don't judge for being 0
found = True found = True
array_name = arr
break break
if found: if found:
@ -1447,8 +1443,8 @@ class CombinedCallsCheck:
# More compelling if close together.. # More compelling if close together..
if call.line_number>prev.line_number and call.line_number-prev.line_number <= 4: if call.line_number>prev.line_number and call.line_number-prev.line_number <= 4:
scope_different = False scope_different = False
for l in range(prev.line_number, call.line_number-1): for no in range(prev.line_number, call.line_number-1):
if lines[l].find('{') != -1 or lines[l].find('}') != -1 or lines[l].find('else') != -1 or lines[l].find('break;') != -1 or lines[l].find('if ') != -1: if lines[no].find('{') != -1 or lines[no].find('}') != -1 or lines[no].find('else') != -1 or lines[no].find('break;') != -1 or lines[no].find('if ') != -1:
scope_different = True scope_different = True
break break
# Also more compelling if check for and scope changes { } in lines in-between? # Also more compelling if check for and scope changes { } in lines in-between?
@ -1668,7 +1664,7 @@ def find_field_arrays(filename, all_fields, all_hf):
for m in matches: for m in matches:
name = m.group(1) name = m.group(1)
# Ignore if not used in a call to an _add_bitmask_ API # Ignore if not used in a call to an _add_bitmask_ API
if not name in all_fields: if name not in all_fields:
continue continue
fields_text = m.group(2) fields_text = m.group(2)
@ -1944,7 +1940,7 @@ elif args.open:
# Only interested in dissector files. # Only interested in dissector files.
files_staged = list(filter(lambda f : is_dissector_file(f), files_staged)) files_staged = list(filter(lambda f : is_dissector_file(f), files_staged))
for f in files_staged: for f in files_staged:
if not f in files: if f not in files:
files.append(f) files.append(f)
else: else:
# Find all dissector files. # Find all dissector files.

View File

@ -207,7 +207,7 @@ elif args.open:
# Only interested in dissector files. # Only interested in dissector files.
files_staged = list(filter(lambda f : is_dissector_file(f), files_staged)) files_staged = list(filter(lambda f : is_dissector_file(f), files_staged))
for f in files_staged: for f in files_staged:
if not f in files: if f not in files:
files.append(f) files.append(f)
else: else:
# Find all dissector files from folder. # Find all dissector files from folder.

View File

@ -103,7 +103,7 @@ def convert_file(file):
except UnicodeDecodeError: except UnicodeDecodeError:
sys.stderr.write(f"{file} isn't valid UTF-8.\n") sys.stderr.write(f"{file} isn't valid UTF-8.\n")
return return
except: except Exception:
sys.stderr.write(f'Unable to open {file}.\n') sys.stderr.write(f'Unable to open {file}.\n')
return return

View File

@ -18,7 +18,6 @@ import sys
import shutil import shutil
import argparse import argparse
import signal import signal
import re
from pathlib import Path from pathlib import Path
@ -190,8 +189,6 @@ def test_file(filename):
# Don't want to delete 'self-includes', so prepare filename. # Don't want to delete 'self-includes', so prepare filename.
module_name = Path(filename).stem module_name = Path(filename).stem
extension = Path(filename).suffix
module_header = module_name + '.h' module_header = module_name + '.h'
# Loop around, finding all possible include lines to comment out # Loop around, finding all possible include lines to comment out

View File

@ -16,10 +16,8 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import argparse import argparse
import io
import re import re
import subprocess import subprocess
import sys
def get_git_authors(): def get_git_authors():

View File

@ -13,9 +13,7 @@ The Bluetooth SIG Repository: https://bitbucket.org/bluetooth-SIG/public/src/mai
and processes the YAML into human-readable strings to go into packet-bluetooth.c. and processes the YAML into human-readable strings to go into packet-bluetooth.c.
''' '''
import re
import sys import sys
import string
import urllib.request, urllib.error, urllib.parse import urllib.request, urllib.error, urllib.parse
import yaml import yaml

View File

@ -41,7 +41,6 @@ def open_url_zipped(url):
return zipfile.ZipFile(io.BytesIO(body)) return zipfile.ZipFile(io.BytesIO(body))
def main(): def main():
this_dir = os.path.dirname(__file__)
isobus_output_path = os.path.join('epan', 'dissectors', 'packet-isobus-parameters.h') isobus_output_path = os.path.join('epan', 'dissectors', 'packet-isobus-parameters.h')
isobus_zip_url = [ "https://www.isobus.net/isobus/attachments/", "isoExport_csv.zip"] isobus_zip_url = [ "https://www.isobus.net/isobus/attachments/", "isoExport_csv.zip"]
@ -132,7 +131,7 @@ def main():
pgn_id, pgn_name, = row[:2] pgn_id, pgn_name, = row[:2]
if not pgn_name.startswith("Proprietary B"): if not pgn_name.startswith("Proprietary B"):
pgn_names[int(pgn_id)] = pgn_name.replace("\"","'") pgn_names[int(pgn_id)] = pgn_name.replace("\"","'")
except: except Exception:
pass pass
# prepare output file # prepare output file
@ -164,7 +163,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_industry_groups_ext = VALUE_STRING_EXT_INIT(_isobus_industry_groups);\n\n"); output_fd.write("static value_string_ext isobus_industry_groups_ext = VALUE_STRING_EXT_INIT(_isobus_industry_groups);\n\n")
# Write Vehicle System Names # Write Vehicle System Names
output_fd.write("/* key: 256 * Industry-Group-ID + Vehicle-Group-ID */\n") output_fd.write("/* key: 256 * Industry-Group-ID + Vehicle-Group-ID */\n")
@ -175,7 +174,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_vehicle_systems_ext = VALUE_STRING_EXT_INIT(_isobus_vehicle_systems);\n\n"); output_fd.write("static value_string_ext isobus_vehicle_systems_ext = VALUE_STRING_EXT_INIT(_isobus_vehicle_systems);\n\n")
# Write Global Name Functions # Write Global Name Functions
output_fd.write("static const value_string _isobus_global_name_functions[] = {\n") output_fd.write("static const value_string _isobus_global_name_functions[] = {\n")
@ -185,7 +184,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_global_name_functions_ext = VALUE_STRING_EXT_INIT(_isobus_global_name_functions);\n\n"); output_fd.write("static value_string_ext isobus_global_name_functions_ext = VALUE_STRING_EXT_INIT(_isobus_global_name_functions);\n\n")
# IG Specific Global Name Functions # IG Specific Global Name Functions
output_fd.write("/* key: 65536 * Industry-Group-ID + 256 * Vehicle-System-ID + Function-ID */\n") output_fd.write("/* key: 65536 * Industry-Group-ID + 256 * Vehicle-System-ID + Function-ID */\n")
@ -196,7 +195,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_ig_specific_name_functions_ext = VALUE_STRING_EXT_INIT(_isobus_ig_specific_name_functions);\n\n"); output_fd.write("static value_string_ext isobus_ig_specific_name_functions_ext = VALUE_STRING_EXT_INIT(_isobus_ig_specific_name_functions);\n\n")
# Write Manufacturers # Write Manufacturers
output_fd.write("static const value_string _isobus_manufacturers[] = {\n") output_fd.write("static const value_string _isobus_manufacturers[] = {\n")
@ -206,7 +205,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_manufacturers_ext = VALUE_STRING_EXT_INIT(_isobus_manufacturers);\n\n"); output_fd.write("static value_string_ext isobus_manufacturers_ext = VALUE_STRING_EXT_INIT(_isobus_manufacturers);\n\n")
# PGN Names # PGN Names
output_fd.write("static const value_string _isobus_pgn_names[] = {\n") output_fd.write("static const value_string _isobus_pgn_names[] = {\n")
@ -216,7 +215,7 @@ def main():
output_fd.write(" { 0, NULL }\n") output_fd.write(" { 0, NULL }\n")
output_fd.write("};\n") output_fd.write("};\n")
output_fd.write("static value_string_ext isobus_pgn_names_ext = VALUE_STRING_EXT_INIT(_isobus_pgn_names);\n\n"); output_fd.write("static value_string_ext isobus_pgn_names_ext = VALUE_STRING_EXT_INIT(_isobus_pgn_names);\n\n")
output_fd.write("#endif /* __PACKET_ISOBUS_PARAMETERS_H__ */") output_fd.write("#endif /* __PACKET_ISOBUS_PARAMETERS_H__ */")
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -230,7 +230,6 @@ def prefix_to_oui(prefix, prefix_map):
return '{}/{:d}'.format(oui, int(pfx_len)), kind return '{}/{:d}'.format(oui, int(pfx_len)), kind
def main(): def main():
this_dir = os.path.dirname(__file__)
manuf_path = os.path.join('epan', 'manuf-data.c') manuf_path = os.path.join('epan', 'manuf-data.c')
ieee_d = { ieee_d = {
@ -246,7 +245,7 @@ def main():
MA_S: {}, MA_S: {},
} }
min_total = 35000; # 35830 as of 2018-09-05 min_total = 35000 # 35830 as of 2018-09-05
total_added = 0 total_added = 0
# Add IEEE entries from each of their databases # Add IEEE entries from each of their databases

View File

@ -9,6 +9,14 @@
# #
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import sys
import getopt
import csv
import re
import collections
import urllib.request, urllib.error, urllib.parse
import codecs
iana_svc_url = 'https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv' iana_svc_url = 'https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv'
__doc__ = '''\ __doc__ = '''\
@ -18,13 +26,6 @@ url defaults to
%s %s
''' % (iana_svc_url) ''' % (iana_svc_url)
import sys
import getopt
import csv
import re
import collections
import urllib.request, urllib.error, urllib.parse
import codecs
services_file = 'epan/services-data.c' services_file = 'epan/services-data.c'
@ -105,7 +106,7 @@ def parse_rows(svc_fd):
if description == service or description == service.replace("-", " "): if description == service or description == service.replace("-", " "):
description = None description = None
if not port in services_map: if port not in services_map:
services_map[port] = collections.OrderedDict() services_map[port] = collections.OrderedDict()
# Remove some duplicates (first entry wins) # Remove some duplicates (first entry wins)
@ -117,7 +118,7 @@ def parse_rows(svc_fd):
if proto_exists: if proto_exists:
continue continue
if not service in services_map[port]: if service not in services_map[port]:
services_map[port][service] = [description] services_map[port][service] = [description]
services_map[port][service].append(proto) services_map[port][service].append(proto)

View File

@ -239,7 +239,7 @@ def xml2obj(src):
def get_req_resp_keys(self, req_resp): def get_req_resp_keys(self, req_resp):
for field in self._children: for field in self._children:
key = field.get_req_resp_key() key = field.get_req_resp_key()
if not key is None and not key in req_resp: if key is not None and key not in req_resp:
req_resp.append(key) req_resp.append(key)
def declaration(self): def declaration(self):
@ -292,7 +292,7 @@ def xml2obj(src):
self.decr_indent() self.decr_indent()
ret += self.indent_out('}\n') ret += self.indent_out('}\n')
return ret; return ret
class Integer(DataNode): class Integer(DataNode):
def __init__(self): def __init__(self):
@ -343,12 +343,12 @@ def xml2obj(src):
ret += self.indent_out('{\n') ret += self.indent_out('{\n')
self.incr_indent() self.incr_indent()
variable = 'counter_%d' %indentation variable = 'counter_%d' %indentation
ret += self.indent_out('uint32_t %s = 0;\n' %(variable)); ret += self.indent_out('uint32_t %s = 0;\n' %(variable))
if self.size_fieldname: if self.size_fieldname:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref:%s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, size, self.size_fieldname)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref:%s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, size, self.size_fieldname))
else: else:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size))
ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable)); ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable))
if self.basemessage.dynamic == "no" and self.size_fieldname: if self.basemessage.dynamic == "no" and self.size_fieldname:
self.incr_indent() self.incr_indent()
ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname)) ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname))
@ -417,7 +417,6 @@ def xml2obj(src):
def declaration(self): def declaration(self):
ret = '' ret = ''
prevvalue = 0
enum_sizes = {'uint32':4,'uint16':2,'uint8':1} enum_sizes = {'uint32':4,'uint16':2,'uint8':1}
if self.type in enum_sizes: if self.type in enum_sizes:
self.intsize = enum_sizes[self.type] self.intsize = enum_sizes[self.type]
@ -477,12 +476,12 @@ def xml2obj(src):
ret += self.indent_out('{\n') ret += self.indent_out('{\n')
self.incr_indent() self.incr_indent()
variable = 'counter_%d' %indentation variable = 'counter_%d' %indentation
ret += self.indent_out('uint32_t %s = 0;\n' %(variable)); ret += self.indent_out('uint32_t %s = 0;\n' %(variable))
if self.size_fieldname: if self.size_fieldname:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref: %s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, size, self.size_fieldname)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref: %s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, size, self.size_fieldname))
else: else:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size))
ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable)); ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable))
if self.basemessage.dynamic == "no" and self.size_fieldname: if self.basemessage.dynamic == "no" and self.size_fieldname:
self.incr_indent() self.incr_indent()
ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname)) ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname))
@ -755,9 +754,9 @@ def xml2obj(src):
def dissect(self): def dissect(self):
ret = '' ret = ''
if self.make_additional_info == "yes": if self.make_additional_info == "yes":
ret += self.indent_out('read_skinny_ipv4or6(cursor, &%s);\n' %(self.name)); ret += self.indent_out('read_skinny_ipv4or6(cursor, &%s);\n' %(self.name))
ret += self.indent_out('dissect_skinny_ipv4or6(cursor, hf_skinny_%s_ipv4, hf_skinny_%s_ipv6);\n' %(self.name, self.name)); ret += self.indent_out('dissect_skinny_ipv4or6(cursor, hf_skinny_%s_ipv4, hf_skinny_%s_ipv6);\n' %(self.name, self.name))
return ret; return ret
class XML(DataNode): class XML(DataNode):
def __init__(self): def __init__(self):
@ -848,7 +847,7 @@ def xml2obj(src):
self.incr_indent() self.incr_indent()
if debug: if debug:
ret += self.indent_out('/* start struct : %s / size: %d */\n' %(self.name, self.intsize)) ret += self.indent_out('/* start struct : %s / size: %d */\n' %(self.name, self.intsize))
ret += self.indent_out('uint32_t %s = 0;\n' %(variable)); ret += self.indent_out('uint32_t %s = 0;\n' %(variable))
if self.size_fieldname: if self.size_fieldname:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref:%s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, self.maxsize, self.size_fieldname)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [ref:%s = %%d, max:%s]", %s);\n' %(self.name, self.size_fieldname, self.maxsize, self.size_fieldname))
if self.maxsize: if self.maxsize:
@ -859,7 +858,7 @@ def xml2obj(src):
else: else:
ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size)) ret += self.indent_out('ptvcursor_add_text_with_subtree(cursor, SUBTREE_UNDEFINED_LENGTH, ett_skinny_tree, "%s [max:%s]");\n' %(self.name, size))
ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable)); ret += self.indent_out('for (%s = 0; %s < %s; %s++) {\n' %(variable, variable, size, variable))
if self.basemessage.dynamic == "no" and self.size_fieldname: if self.basemessage.dynamic == "no" and self.size_fieldname:
self.incr_indent() self.incr_indent()
ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname)) ret += self.indent_out('if (%s < %s) {\n' %(variable,self.size_fieldname))
@ -906,7 +905,7 @@ def xml2obj(src):
if self.size_fieldname: if self.size_fieldname:
ret += self.indent_out('} else {\n') ret += self.indent_out('} else {\n')
self.incr_indent() self.incr_indent()
ret += self.indent_out('ptvcursor_advance(cursor, (%s * %s));%s\n' %(self.size_fieldname, self.intsize, ' /* guard kicked in -> skip the rest */' if debug else '')); ret += self.indent_out('ptvcursor_advance(cursor, (%s * %s));%s\n' %(self.size_fieldname, self.intsize, ' /* guard kicked in -> skip the rest */' if debug else ''))
self.decr_indent() self.decr_indent()
ret += self.indent_out('} /* end struct size guard */\n' if debug else '}\n') ret += self.indent_out('} /* end struct size guard */\n' if debug else '}\n')
@ -948,7 +947,6 @@ def xml2obj(src):
def dissect(self): def dissect(self):
ret = '' ret = ''
ifblock = self.indent_out('if') ifblock = self.indent_out('if')
skip = 0
#ret += self.indent_out('/* Union : %s / maxsize: %s */\n' %(self.name, self.maxsize)) #ret += self.indent_out('/* Union : %s / maxsize: %s */\n' %(self.name, self.maxsize))
if (self.fields is not None and len(self.fields)): if (self.fields is not None and len(self.fields)):

View File

@ -7,7 +7,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import sys import sys
import os
import fnmatch import fnmatch
IGNORE_CONF = "pre-commit-ignore.conf" IGNORE_CONF = "pre-commit-ignore.conf"
@ -29,8 +28,8 @@ def load_checkignore(path):
patterns = f.read() patterns = f.read()
except OSError as err: except OSError as err:
sys.exit(str(err)) sys.exit(str(err))
ign = [l.strip() for l in patterns.splitlines()] ign = [line.strip() for line in patterns.splitlines()]
ign = [l for l in ign if l and not l.startswith("#")] ign = [line for line in ign if line and not line.startswith("#")]
return ign return ign
ignore_list = load_checkignore(ignore_path) ignore_list = load_checkignore(ignore_path)

View File

@ -19,7 +19,6 @@ import json
import os import os
import subprocess import subprocess
import sys import sys
import tempfile
import urllib.request import urllib.request
import re import re
@ -227,8 +226,8 @@ def main():
try: try:
with open(args.commitmsg) as f: with open(args.commitmsg) as f:
return 0 if verify_body(f.read()) else 1 return 0 if verify_body(f.read()) else 1
except: except Exception:
print("Couldn't verify body of message from file '", + args.commitmsg + "'"); print("Couldn't verify body of message from file '", + args.commitmsg + "'")
return 1 return 1