Creates a cls instance, use the `alternative` if that fails.
(cls, filename)
| 1340 | return newcls |
| 1341 | |
| 1342 | def __call__(cls, filename): |
| 1343 | # type: (Union[IO[bytes], str]) -> Any |
| 1344 | """Creates a cls instance, use the `alternative` if that |
| 1345 | fails. |
| 1346 | |
| 1347 | """ |
| 1348 | i = cls.__new__( |
| 1349 | cls, |
| 1350 | cls.__name__, |
| 1351 | cls.__bases__, |
| 1352 | cls.__dict__ # type: ignore |
| 1353 | ) |
| 1354 | filename, fdesc, magic = cls.open(filename) |
| 1355 | if not magic: |
| 1356 | raise Scapy_Exception( |
| 1357 | "No data could be read!" |
| 1358 | ) |
| 1359 | try: |
| 1360 | i.__init__(filename, fdesc, magic) |
| 1361 | return i |
| 1362 | except (Scapy_Exception, EOFError): |
| 1363 | pass |
| 1364 | |
| 1365 | if "alternative" in cls.__dict__: |
| 1366 | cls = cls.__dict__["alternative"] |
| 1367 | i = cls.__new__( |
| 1368 | cls, |
| 1369 | cls.__name__, |
| 1370 | cls.__bases__, |
| 1371 | cls.__dict__ # type: ignore |
| 1372 | ) |
| 1373 | try: |
| 1374 | i.__init__(filename, fdesc, magic) |
| 1375 | return i |
| 1376 | except (Scapy_Exception, EOFError): |
| 1377 | pass |
| 1378 | |
| 1379 | raise Scapy_Exception("Not a supported capture file") |
| 1380 | |
| 1381 | @staticmethod |
| 1382 | def open(fname # type: Union[IO[bytes], str] |
nothing calls this directly
no test coverage detected