Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return PingStats(
destination=destination,
packet_transmit=packet_transmit,
packet_receive=packet_receive,
duplicates=duplicates,
rtt_min=float(parse_list[1]),
rtt_avg=float(parse_list[5]),
rtt_max=float(parse_list[3]),
icmp_replies=icmp_replies,
)
def _parse_destination(self, stats_headline):
return stats_headline.lstrip("Ping statistics for ").rstrip(":")
class MacOsPingParser(PingParser):
@property
def _parser_name(self):
return "macOS"
@property
def _icmp_reply_pattern(self):
return (
" from .+?: "
+ self._ICMP_SEQ_PATTERN
+ " "
+ self._TTL_PATTERN
+ " "
+ self._TIME_PATTERN
)
@property
packet_pattern = (
pp.SkipTo(pp.Word("+" + pp.nums) + pp.Literal("duplicates,"))
+ pp.Word("+" + pp.nums)
+ pp.Literal("duplicates,")
)
try:
duplicate_parse_list = packet_pattern.parseString(_to_unicode(line))
except pp.ParseException:
return 0
return int(duplicate_parse_list[-2].strip("+"))
class NullPingParser(PingParser):
@property
def _parser_name(self):
return "null"
@property
def _icmp_reply_pattern(self):
return ""
@property
def _stats_headline_pattern(self):
return ""
@property
def _is_support_packet_duplicate(self): # pragma: no cover
return False
parse_list = rtt_pattern.parseString(_to_unicode(rtt_line))
return PingStats(
destination=destination,
packet_transmit=packet_transmit,
packet_receive=packet_receive,
duplicates=duplicates,
rtt_min=float(parse_list[1]),
rtt_avg=float(parse_list[3]),
rtt_max=float(parse_list[5]),
rtt_mdev=float(parse_list[7]),
icmp_replies=icmp_replies,
)
class WindowsPingParser(PingParser):
@property
def _parser_name(self):
return "Windows"
@property
def _icmp_reply_pattern(self):
return " from .+?: " + self._TTL_PATTERN + " " + self._TIME_PATTERN
@property
def _stats_headline_pattern(self):
return "^Ping statistics for "
@property
def _is_support_packet_duplicate(self):
return False
@property
def _stats_headline_pattern(self):
return ""
@property
def _is_support_packet_duplicate(self): # pragma: no cover
return False
def parse(self, ping_message): # pragma: no cover
pass
def _preprocess_parse_stats(self, lines): # pragma: no cover
pass
class LinuxPingParser(PingParser):
@property
def _parser_name(self):
return "Linux"
@property
def _icmp_reply_pattern(self):
return (
r"(?P\[[0-9\.]+\])?\s?.+ from .+?: "
+ self._ICMP_SEQ_PATTERN
+ " "
+ self._TTL_PATTERN
+ " "
+ self._TIME_PATTERN
)
@property