Skip to content

Commit 4a729cf

Browse files
authored
Merge branch 'master' into bugfix/ensure-close-async
2 parents 7142c5b + 5bef368 commit 4a729cf

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

src/pyshark/capture/capture.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import contextlib
3+
import inspect
34
import os
45
import threading
56
import subprocess
@@ -292,7 +293,10 @@ async def _go_through_packets_from_fd(self, fd, packet_callback, packet_count=No
292293
if packet:
293294
packets_captured += 1
294295
try:
295-
packet_callback(packet)
296+
if inspect.iscoroutinefunction(packet_callback):
297+
await packet_callback(packet)
298+
else:
299+
packet_callback(packet)
296300
except StopCapture:
297301
self._log.debug("User-initiated capture stop in callback")
298302
break

src/pyshark/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# (Linux): /usr/sbin/tshark
66
# (Linux): /usr/lib/tshark/tshark
77
# (Linux): /usr/local/bin/tshark
8+
# (Linux): /bin/tshark
89
# (Windows): %ProgramFiles%\Wireshark\tshark.exe
910
# (Windows): %ProgramFiles(x86)%\Wireshark\tshark.exe
1011
tshark_path = C:\Program Files\Wireshark\tshark.exe

src/pyshark/tshark/output_parser/tshark_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, parse_summaries=False):
2222
self._psml_structure = None
2323

2424
async def get_packets_from_stream(self, stream, existing_data, got_first_packet=True):
25-
if self._parse_summaries:
25+
if self._parse_summaries and self._psml_structure is None:
2626
existing_data = await self._get_psml_struct(stream)
2727
return await super().get_packets_from_stream(stream, existing_data, got_first_packet=got_first_packet)
2828

src/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="pyshark",
9-
version="0.6",
9+
version="0.6.1",
1010
packages=find_packages(),
1111
package_data={'': ['*.ini', '*.pcapng']},
1212
install_requires=['lxml', 'termcolor', 'packaging', 'appdirs'],

tests/test_cap_operations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def test_packet_callback_called_for_each_packet(lazy_simple_capture):
1717
assert mock_callback.call_count == 24
1818

1919

20+
def test_async_packet_callback_called_for_each_packet(lazy_simple_capture):
21+
# Test cap has 24 packets
22+
mock_callback = mock.AsyncMock()
23+
lazy_simple_capture.apply_on_packets(mock_callback)
24+
assert mock_callback.call_count == 24
25+
mock_callback.assert_awaited()
26+
27+
2028
def test_apply_on_packet_stops_on_timeout(lazy_simple_capture):
2129
def wait(pkt):
2230
time.sleep(5)

0 commit comments

Comments
 (0)