From 0180c9caf017c5b138d1f9e810bbbbecf0dc1332 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 18 Jul 2018 13:25:24 -0600 Subject: [PATCH] Fix HtmlSession --- netarch/ip.py | 11 +++++++++-- netarch/trilobytes.py | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/netarch/ip.py b/netarch/ip.py index 0d1602b..7b3a8d4 100644 --- a/netarch/ip.py +++ b/netarch/ip.py @@ -8,6 +8,7 @@ import socket import warnings import heapq import time +import io try: import pcap except ImportError: @@ -564,12 +565,16 @@ class Packet: if self.parts: dl = len(self.parts[-1]) p = [] + xp = [] for x in self.parts[:-1]: if x == dl: p.append('%3d!' % x) + xp.append('%3x!' % x) else: p.append('%3d' % x) - print(' parts: (%s) +%d(0x%x) octets' % (','.join(p), dl, dl)) + xp.append('%3x' % x) + print(' parts: (%s) +%d octets' % (','.join(p), dl)) + print(' 0xparts: (%s) +%x octets' % (','.join(xp), dl)) keys = sorted(self.params) for k in keys: @@ -721,7 +726,9 @@ class Session: class HtmlSession(Session): def __init__(self, frame): Session.__init__(self, frame) - self.sessfd = self.open_out('session.html') + fd = self.open_out('session.html') + fbuf = io.BufferedWriter(fd, 1024) + self.sessfd = io.TextIOWrapper(fbuf, encoding="utf-8") self.sessfd.write(''' ' % (self.missing(), len(self)) + def decode(self, codec): + return bytes(self).decode(codec) + def missing(self): """ >>> TriloBytes(b'abc').missing()