MCPcopy Index your code
hub / github.com/secdev/scapy / _pkt_ls

Function _pkt_ls

scapy/packet.py:2369–2444  ·  view source on GitHub ↗

Internal function used to resolve `fields_desc` to display it. :param obj: a packet object or class :returns: a list containing tuples [(name, clsname, clsname_extras, default, long_attrs)]

(obj,  # type: Union[Packet, Type[Packet]]
            verbose=False,  # type: bool
            )

Source from the content-addressed store, hash-verified

2367
2368
2369def _pkt_ls(obj, # type: Union[Packet, Type[Packet]]
2370 verbose=False, # type: bool
2371 ):
2372 # type: (...) -> List[Tuple[str, Type[AnyField], str, str, List[str]]] # noqa: E501
2373 """Internal function used to resolve `fields_desc` to display it.
2374
2375 :param obj: a packet object or class
2376 :returns: a list containing tuples [(name, clsname, clsname_extras,
2377 default, long_attrs)]
2378 """
2379 is_pkt = isinstance(obj, Packet)
2380 if not issubtype(obj, Packet) and not is_pkt:
2381 raise ValueError
2382 fields = []
2383 for f in obj.fields_desc:
2384 cur_fld = f
2385 attrs = [] # type: List[str]
2386 long_attrs = [] # type: List[str]
2387 while isinstance(cur_fld, (Emph, ConditionalField)):
2388 if isinstance(cur_fld, ConditionalField):
2389 attrs.append(cur_fld.__class__.__name__[:4])
2390 cur_fld = cur_fld.fld
2391 name = cur_fld.name
2392 default = cur_fld.default
2393 if verbose and isinstance(cur_fld, EnumField) \
2394 and hasattr(cur_fld, "i2s") and cur_fld.i2s:
2395 if len(cur_fld.i2s or []) < 50:
2396 long_attrs.extend(
2397 "%s: %d" % (strval, numval)
2398 for numval, strval in
2399 sorted(cur_fld.i2s.items())
2400 )
2401 elif isinstance(cur_fld, MultiEnumField):
2402 if isinstance(obj, Packet):
2403 obj_pkt = obj
2404 else:
2405 obj_pkt = obj()
2406 fld_depend = cur_fld.depends_on(obj_pkt)
2407 attrs.append("Depends on %s" % fld_depend)
2408 if verbose:
2409 cur_i2s = cur_fld.i2s_multi.get(
2410 cur_fld.depends_on(obj_pkt), {}
2411 )
2412 if len(cur_i2s) < 50:
2413 long_attrs.extend(
2414 "%s: %d" % (strval, numval)
2415 for numval, strval in
2416 sorted(cur_i2s.items())
2417 )
2418 elif verbose and isinstance(cur_fld, FlagsField):
2419 names = cur_fld.names
2420 long_attrs.append(", ".join(names))
2421 elif isinstance(cur_fld, MultipleTypeField):
2422 default = cur_fld.dflt.default
2423 attrs.append(", ".join(
2424 x[0].__class__.__name__ for x in
2425 itertools.chain(cur_fld.flds, [(cur_fld.dflt,)])
2426 ))

Callers 2

get_fields_descFunction · 0.90
lsFunction · 0.85

Calls 6

issubtypeFunction · 0.90
extendMethod · 0.80
itemsMethod · 0.80
joinMethod · 0.80
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected