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

Method _command

scapy/packet.py:1727–1779  ·  view source on GitHub ↗

Internal method used to generate command() and json()

(self, json=False)

Source from the content-addressed store, hash-verified

1725 self.payload.dissection_done(pp)
1726
1727 def _command(self, json=False):
1728 # type: (bool) -> List[Tuple[str, Any]]
1729 """
1730 Internal method used to generate command() and json()
1731 """
1732 f = []
1733 iterator: Iterator[Tuple[str, Any]]
1734 if json:
1735 iterator = ((x.name, self.getfieldval(x.name)) for x in self.fields_desc)
1736 else:
1737 iterator = iter(self.fields.items())
1738 for fn, fv in iterator:
1739 fld = self.get_field(fn)
1740 if isinstance(fv, (list, dict, set)) and not fv and not fld.default:
1741 continue
1742 if isinstance(fv, Packet):
1743 if json:
1744 fv = {k: v for (k, v) in fv._command(json=True)}
1745 else:
1746 fv = fv.command()
1747 elif fld.islist and fld.holds_packets and isinstance(fv, list):
1748 if json:
1749 fv = [
1750 {k: v for (k, v) in x}
1751 for x in map(lambda y: Packet._command(y, json=True), fv)
1752 ]
1753 else:
1754 fv = "[%s]" % ",".join(map(Packet.command, fv))
1755 elif fld.islist and isinstance(fv, list):
1756 if json:
1757 fv = [
1758 getattr(x, 'command', lambda: repr(x))()
1759 for x in fv
1760 ]
1761 else:
1762 fv = "[%s]" % ",".join(
1763 getattr(x, 'command', lambda: repr(x))()
1764 for x in fv
1765 )
1766 elif isinstance(fv, FlagValue):
1767 fv = int(fv)
1768 elif callable(getattr(fv, 'command', None)):
1769 fv = fv.command(json=json)
1770 else:
1771 if json:
1772 if isinstance(fv, bytes):
1773 fv = fv.decode("utf-8", errors="backslashreplace")
1774 else:
1775 fv = fld.i2h(self, fv)
1776 else:
1777 fv = repr(fld.i2h(self, fv))
1778 f.append((fn, fv))
1779 return f
1780
1781 def command(self):
1782 # type: () -> str

Callers 2

commandMethod · 0.95
jsonMethod · 0.95

Calls 8

getfieldvalMethod · 0.95
get_fieldMethod · 0.95
itemsMethod · 0.80
joinMethod · 0.80
decodeMethod · 0.80
commandMethod · 0.45
i2hMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected