Internal method that shows or dumps a hierarchical view of a packet. Called by show. :param dump: determine if it prints or returns the string value :param int indent: the size of indentation for each layer :param str lvl: additional information about the la
(self,
dump=False, # type: bool
indent=3, # type: int
lvl="", # type: str
label_lvl="", # type: str
first_call=True # type: bool
)
| 1432 | self.show(*args, **kargs) |
| 1433 | |
| 1434 | def _show_or_dump(self, |
| 1435 | dump=False, # type: bool |
| 1436 | indent=3, # type: int |
| 1437 | lvl="", # type: str |
| 1438 | label_lvl="", # type: str |
| 1439 | first_call=True # type: bool |
| 1440 | ): |
| 1441 | # type: (...) -> Optional[str] |
| 1442 | """ |
| 1443 | Internal method that shows or dumps a hierarchical view of a packet. |
| 1444 | Called by show. |
| 1445 | |
| 1446 | :param dump: determine if it prints or returns the string value |
| 1447 | :param int indent: the size of indentation for each layer |
| 1448 | :param str lvl: additional information about the layer lvl |
| 1449 | :param str label_lvl: additional information about the layer fields |
| 1450 | :param first_call: determine if the current function is the first |
| 1451 | :return: return a hierarchical view if dump, else print it |
| 1452 | """ |
| 1453 | |
| 1454 | if dump: |
| 1455 | from scapy.themes import ColorTheme, AnsiColorTheme |
| 1456 | ct: ColorTheme = AnsiColorTheme() # No color for dump output |
| 1457 | else: |
| 1458 | ct = conf.color_theme |
| 1459 | s = "%s%s %s %s\n" % (label_lvl, |
| 1460 | ct.punct("###["), |
| 1461 | ct.layer_name(self.name), |
| 1462 | ct.punct("]###")) |
| 1463 | fields = self.fields_desc.copy() |
| 1464 | while fields: |
| 1465 | f = fields.pop(0) |
| 1466 | if isinstance(f, ConditionalField) and not f._evalcond(self): |
| 1467 | continue |
| 1468 | if hasattr(f, "fields"): # Field has subfields |
| 1469 | s += "%s %s =\n" % ( |
| 1470 | label_lvl + lvl, |
| 1471 | ct.depreciate_field_name(f.name), |
| 1472 | ) |
| 1473 | lvl += " " * indent * self.show_indent |
| 1474 | for i, fld in enumerate(x for x in f.fields if hasattr(self, x.name)): |
| 1475 | fields.insert(i, fld) |
| 1476 | continue |
| 1477 | if isinstance(f, Emph) or f in conf.emph: |
| 1478 | ncol = ct.emph_field_name |
| 1479 | vcol = ct.emph_field_value |
| 1480 | else: |
| 1481 | ncol = ct.field_name |
| 1482 | vcol = ct.field_value |
| 1483 | pad = max(0, 10 - len(f.name)) * " " |
| 1484 | fvalue = self.getfieldval(f.name) |
| 1485 | if isinstance(fvalue, Packet) or (f.islist and f.holds_packets and isinstance(fvalue, list)): # noqa: E501 |
| 1486 | s += "%s %s%s%s%s\n" % (label_lvl + lvl, |
| 1487 | ct.punct("\\"), |
| 1488 | ncol(f.name), |
| 1489 | pad, |
| 1490 | ct.punct("\\")) |
| 1491 | fvalue_gen = SetGen( |
no test coverage detected