mirror of
https://gitlab.com/prpl-foundation/prplmesh/prplMesh.git
synced 2025-12-20 01:21:22 +08:00
tests:sniffer.py: make sure tlv_struct name is a valid identifier
Some names (ex. 'non-operating_channel ') are not a valid python identifier. Makes sure TlvStruct name is a valid identifier. PPM-1161 -- Signed-off-by: Krystyna Oliinyk <k.oliinyk@inango-systems.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
import subprocess
|
||||
import re
|
||||
from opts import debug, err, status
|
||||
from typing import Callable
|
||||
|
||||
@@ -32,6 +33,7 @@ class TlvStruct:
|
||||
value = [TlvStruct(value, level + 1)]
|
||||
else:
|
||||
value = [TlvStruct(v, level + 1) for k, v in value.items()]
|
||||
name = self.valid_var_name(name)
|
||||
setattr(self, name, value)
|
||||
|
||||
def __repr__(self):
|
||||
@@ -43,6 +45,8 @@ class TlvStruct:
|
||||
def __eq__(self, other):
|
||||
return self._d() == other._d()
|
||||
|
||||
def valid_var_name(self, varStr): return re.sub(r'\W|^(?=\d)', '_', varStr)
|
||||
|
||||
|
||||
class Tlv(TlvStruct):
|
||||
'''Represents an IEEE1905.1 TLV in a Packet.'''
|
||||
|
||||
Reference in New Issue
Block a user