MCPcopy Create free account
hub / github.com/secdev/scapy / _build_config_representation

Method _build_config_representation

scapy/fields.py:1246–1287  ·  view source on GitHub ↗
(self, config)

Source from the content-addressed store, hash-verified

1244 __slots__ = ['eval_fn']
1245
1246 def _build_config_representation(self, config):
1247 # type: (Dict[str, Any]) -> None
1248 assoc_table = dict()
1249 for key in config:
1250 value_spec = config[key]
1251
1252 value_spec_type = type(value_spec)
1253
1254 if value_spec_type is int:
1255 if value_spec < 0 or value_spec > 255:
1256 raise FieldValueRangeException('given field value {} invalid - ' # noqa: E501
1257 'must be in range [0..255]'.format(value_spec)) # noqa: E501
1258 assoc_table[value_spec] = key
1259
1260 elif value_spec_type is list:
1261 for value in value_spec:
1262 if value < 0 or value > 255:
1263 raise FieldValueRangeException('given field value {} invalid - ' # noqa: E501
1264 'must be in range [0..255]'.format(value)) # noqa: E501
1265 assoc_table[value] = key
1266
1267 elif value_spec_type is tuple:
1268 value_spec_len = len(value_spec)
1269 if value_spec_len != 2:
1270 raise FieldAttributeException('invalid length {} of given config item tuple {} - must be ' # noqa: E501
1271 '(<start-range>, <end-range>).'.format(value_spec_len, value_spec)) # noqa: E501
1272
1273 value_range_start = value_spec[0]
1274 if value_range_start < 0 or value_range_start > 255:
1275 raise FieldValueRangeException('given field value {} invalid - ' # noqa: E501
1276 'must be in range [0..255]'.format(value_range_start)) # noqa: E501
1277
1278 value_range_end = value_spec[1]
1279 if value_range_end < 0 or value_range_end > 255:
1280 raise FieldValueRangeException('given field value {} invalid - ' # noqa: E501
1281 'must be in range [0..255]'.format(value_range_end)) # noqa: E501
1282
1283 for value in range(value_range_start, value_range_end + 1):
1284
1285 assoc_table[value] = key
1286
1287 self.eval_fn = lambda x: assoc_table[x] if x in assoc_table else x
1288
1289 def __init__(self, name, default, config=None):
1290 # type: (str, int, Optional[Dict[str, Any]]) -> None

Callers 1

__init__Method · 0.95

Calls 3

formatMethod · 0.45

Tested by

no test coverage detected