def load_trace(path, *args, **kwargs):
"""Read a packet trace file, return a :class:`wltrace.common.WlTrace` object.
This function first reads the file's magic
(first ``FILE_TYPE_HANDLER`` bytes), and automatically determine the
file type, and call appropriate handler to process the file.
Args:
path (str): the file's path to be loaded.
Returns:
``WlTrace`` object.
"""
with open(path, 'rb') as f:
magic = f.read(MAGIC_LEN)
if magic not in FILE_TYPE_HANDLER:
raise Exception('Unknown file magic: %s' % (binascii.hexlify(magic)))
return FILE_TYPE_HANDLER[magic](path, *args, **kwargs)
评论列表
文章目录