diff --git a/src/pyshark/capture/capture.py b/src/pyshark/capture/capture.py index 0a7037e5..b6c8b4e3 100644 --- a/src/pyshark/capture/capture.py +++ b/src/pyshark/capture/capture.py @@ -1,5 +1,6 @@ import asyncio import contextlib +import inspect import os import threading import subprocess @@ -292,7 +293,10 @@ async def _go_through_packets_from_fd(self, fd, packet_callback, packet_count=No if packet: packets_captured += 1 try: - packet_callback(packet) + if inspect.iscoroutinefunction(packet_callback): + await packet_callback(packet) + else: + packet_callback(packet) except StopCapture: self._log.debug("User-initiated capture stop in callback") break diff --git a/src/pyshark/config.ini b/src/pyshark/config.ini index 6d6b1285..86be2e69 100644 --- a/src/pyshark/config.ini +++ b/src/pyshark/config.ini @@ -5,6 +5,7 @@ # (Linux): /usr/sbin/tshark # (Linux): /usr/lib/tshark/tshark # (Linux): /usr/local/bin/tshark +# (Linux): /bin/tshark # (Windows): %ProgramFiles%\Wireshark\tshark.exe # (Windows): %ProgramFiles(x86)%\Wireshark\tshark.exe tshark_path = C:\Program Files\Wireshark\tshark.exe diff --git a/src/pyshark/tshark/output_parser/tshark_xml.py b/src/pyshark/tshark/output_parser/tshark_xml.py index 51fc6987..795c588e 100644 --- a/src/pyshark/tshark/output_parser/tshark_xml.py +++ b/src/pyshark/tshark/output_parser/tshark_xml.py @@ -22,7 +22,7 @@ def __init__(self, parse_summaries=False): self._psml_structure = None async def get_packets_from_stream(self, stream, existing_data, got_first_packet=True): - if self._parse_summaries: + if self._parse_summaries and self._psml_structure is None: existing_data = await self._get_psml_struct(stream) return await super().get_packets_from_stream(stream, existing_data, got_first_packet=got_first_packet) diff --git a/src/setup.py b/src/setup.py index bd027a68..f98a57e5 100644 --- a/src/setup.py +++ b/src/setup.py @@ -6,7 +6,7 @@ setup( name="pyshark", - version="0.6", + version="0.6.1", packages=find_packages(), package_data={'': ['*.ini', '*.pcapng']}, install_requires=['lxml', 'termcolor', 'packaging', 'appdirs'], diff --git a/tests/test_cap_operations.py b/tests/test_cap_operations.py index e80904e0..a6670f1f 100644 --- a/tests/test_cap_operations.py +++ b/tests/test_cap_operations.py @@ -17,6 +17,14 @@ def test_packet_callback_called_for_each_packet(lazy_simple_capture): assert mock_callback.call_count == 24 +def test_async_packet_callback_called_for_each_packet(lazy_simple_capture): + # Test cap has 24 packets + mock_callback = mock.AsyncMock() + lazy_simple_capture.apply_on_packets(mock_callback) + assert mock_callback.call_count == 24 + mock_callback.assert_awaited() + + def test_apply_on_packet_stops_on_timeout(lazy_simple_capture): def wait(pkt): time.sleep(5)