From c79a2ff89720eae2980aae746f4cdbc331bf0b7d Mon Sep 17 00:00:00 2001 From: "nico@chdir.org" Date: Fri, 2 Aug 2013 19:29:41 +0200 Subject: [PATCH] Implements PEP-0343 --- scapy/utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scapy/utils.py b/scapy/utils.py index 07e3a8ae8..661385671 100644 --- a/scapy/utils.py +++ b/scapy/utils.py @@ -560,7 +560,12 @@ class RawPcapReader: def close(self): return self.f.close() - + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, tracback): + pass + class PcapReader(RawPcapReader): def __init__(self, filename): @@ -673,9 +678,16 @@ class RawPcapWriter: def flush(self): return self.f.flush() + def close(self): return self.f.close() - + + def __enter__(self): + return self + def __exit__(self, exc_type, exc_value, tracback): + self.flush() + + class PcapWriter(RawPcapWriter): def _write_header(self, pkt): if self.linktype == None: