true if self has a layer that is an instance of cls. Superseded by "cls in self" syntax.
(self, cls, _subclass=None)
| 1287 | return layers |
| 1288 | |
| 1289 | def haslayer(self, cls, _subclass=None): |
| 1290 | # type: (Union[Type[Packet], str], Optional[bool]) -> int |
| 1291 | """ |
| 1292 | true if self has a layer that is an instance of cls. |
| 1293 | Superseded by "cls in self" syntax. |
| 1294 | """ |
| 1295 | if _subclass is None: |
| 1296 | _subclass = self.match_subclass or None |
| 1297 | if _subclass: |
| 1298 | match = issubtype |
| 1299 | else: |
| 1300 | match = lambda x, t: bool(x == t) |
| 1301 | if cls is None or match(self.__class__, cls) \ |
| 1302 | or cls in [self.__class__.__name__, self._name]: |
| 1303 | return True |
| 1304 | for f in self.packetfields: |
| 1305 | fvalue_gen = self.getfieldval(f.name) |
| 1306 | if fvalue_gen is None: |
| 1307 | continue |
| 1308 | if not f.islist: |
| 1309 | fvalue_gen = SetGen(fvalue_gen, _iterpacket=0) |
| 1310 | for fvalue in fvalue_gen: |
| 1311 | if isinstance(fvalue, Packet): |
| 1312 | ret = fvalue.haslayer(cls, _subclass=_subclass) |
| 1313 | if ret: |
| 1314 | return ret |
| 1315 | return self.payload.haslayer(cls, _subclass=_subclass) |
| 1316 | |
| 1317 | def getlayer(self, |
| 1318 | cls, # type: Union[int, Type[Packet], str] |
no test coverage detected