From 37b8c8237ab0fcca93c09a9c8094501cf0591f8e Mon Sep 17 00:00:00 2001
From: gpotter2 <gabriel@potter.fr>
Date: Fri, 12 May 2017 18:20:14 +0200
Subject: [PATCH] Add more coverage: operators and logic

---
 scapy/automaton.py |  2 +-
 scapy/pipetool.py  |  2 +-
 test/pipetool.uts  | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/scapy/automaton.py b/scapy/automaton.py
index 08d62ea2..7942a0ac 100644
--- a/scapy/automaton.py
+++ b/scapy/automaton.py
@@ -334,7 +334,7 @@ def select_objects(inputs, remain, customTypes=()):
     if WINDOWS:
         r = []
         def look_for_select():
-            for fd in inputs:
+            for fd in list(inputs):
                 if isinstance(fd, (ObjectPipe, Automaton._IO_fdwrapper) + customTypes):
                     if fd.checkRecv():
                         r.append(fd)
diff --git a/scapy/pipetool.py b/scapy/pipetool.py
index 26306fb0..56c0de75 100644
--- a/scapy/pipetool.py
+++ b/scapy/pipetool.py
@@ -128,7 +128,7 @@ class PipeEngine:
                             STOP_IF_EXHAUSTED = True
                         elif cmd == "A":
                             sources = self.active_sources-exhausted
-                            sources.add(self.__fdr)
+                            sources.add(self)
                         else:
                             warning("Unknown internal pipe engine command: %r. Ignoring." % cmd)
                     elif fd in sources:
diff --git a/test/pipetool.uts b/test/pipetool.uts
index 2d977237..7b25042b 100644
--- a/test/pipetool.uts
+++ b/test/pipetool.uts
@@ -31,6 +31,45 @@ x = p.spawn_Pipe()
 assert len(p.active_pipes) == 3
 assert isinstance(x, Pipe)
 
+= Test exhausted source
+
+s = AutoSource()
+s._gen_data("hello")
+s.is_exhausted = True
+d1 = Drain(name="d1")
+c = ConsoleSink(name="c")
+s > d1 > c
+
+p = PipeEngine(s)
+p.start()
+time.sleep(1)
+p.wait_and_stop()
+
+= Test add_pipe on running instance
+
+test_val = None
+
+class TestSink(Sink):
+    def push(self, msg):
+        global test_val
+        test_val = msg
+
+p = PipeEngine()
+p.start()
+
+s = AutoSource()
+s._gen_data("hello")
+s.is_exhausted = True
+
+d1 = Drain(name="d1")
+c = TestSink(name="c")
+s > d1 > c
+
+p.add(s)
+time.sleep(1)
+p.wait_and_stop()
+assert test_val == "hello"
+
 = Test Operators
 
 s = AutoSource()
@@ -59,6 +98,28 @@ assert len(b.high_sources) == 0
 a
 b
 
+a = AutoSource()
+b = AutoSource()
+a == b
+assert len(a.sinks) == 1
+assert len(a.sources) == 1
+assert len(b.sinks) == 1
+assert len(b.sources) == 1
+
+a = AutoSource()
+b = AutoSource()
+a//b
+assert len(a.high_sinks) == 1
+assert len(a.high_sources) == 1
+assert len(b.high_sinks) == 1
+assert len(b.high_sources) == 1
+
+a = AutoSource()
+b = AutoSource()
+a^b
+assert len(b.trigger_sources) == 1
+assert len(a.trigger_sinks) == 1
+
 = Test doc
 
 s = AutoSource()
-- 
GitLab