Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except AttributeError:
pass
logger.debug("parsing ping result: {}".format(ping_message))
self.__parser = NullPingParser()
if typepy.is_null_string(ping_message):
logger.debug("ping_message is empty")
self.__stats = PingStats()
return self.__stats
ping_lines = _to_unicode(ping_message).splitlines()
parser_class_list = (
LinuxPingParser,
WindowsPingParser,
MacOsPingParser,
AlpineLinuxPingParser,
)
for parser_class in parser_class_list:
self.__parser = parser_class()
try:
self.__stats = self.__parser.parse(ping_lines)
return self.__stats
except ParseError as e:
if e.reason != ParseErrorReason.HEADER_NOT_FOUND:
raise e
except pp.ParseException:
pass
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 AlpineLinuxPingParser(LinuxPingParser):
@property
def _parser_name(self):
return "AlpineLinux"
@property
def _icmp_reply_pattern(self):
return (
" from .+?: " + r"seq=(?P\d+) " + self._TTL_PATTERN + " " + self._TIME_PATTERN
)
@property
def _is_support_packet_duplicate(self):
return True
def parse(self, ping_message):
icmp_replies = self._parse_icmp_reply(ping_message)