From c5e1b99ebd63497f4ce0a1a4ba1465e06cba551b Mon Sep 17 00:00:00 2001
From: Pierre LALET <pierre.lalet@cea.fr>
Date: Sat, 30 Sep 2017 01:41:27 +0200
Subject: [PATCH] Python 3: tests fixes

---
 test/linux.uts | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/test/linux.uts b/test/linux.uts
index 22414465..2706f35f 100644
--- a/test/linux.uts
+++ b/test/linux.uts
@@ -12,10 +12,13 @@
 ~ automaton netaccess linux needs_root
 * This test retries on failure because it often fails
 
+from __future__ import print_function
 import os
 import time
 import signal
 
+from scapy.modules.six.moves import range
+
 def handler(signum, stack_frame):
     raise Exception("Timer expired !")
 
@@ -28,12 +31,12 @@ IPTABLE_RULE = "iptables -%c INPUT -s %s -p tcp --sport 80 -j DROP"
 assert(os.system(IPTABLE_RULE % ('A', SECDEV_IP4)) == 0)
 
 success = False
-for i in xrange(10):
+for i in range(10):
     tmp = signal.alarm(5)
     try:
         r, w = os.pipe()
         t = TCP_client(SECDEV_IP4, 80, external_fd={ "tcp": (r,w) })
-        tmp = os.write(w, "HEAD / HTTP/1.0\r\n\r\n")
+        tmp = os.write(w, b"HEAD / HTTP/1.0\r\n\r\n")
         t.runbg()
         time.sleep(0.5)
         response = os.read(r, 4096)
@@ -41,13 +44,13 @@ for i in xrange(10):
         t.stop()
         os.close(r)
         os.close(w)
-        if response.startswith("HTTP/1.1 200 OK"):
+        if response.startswith(b"HTTP/1.1 200 OK"):
             success = True
             break
         else:
             time.sleep(0.5)
     except Exception as e:
-        print e
+        print(e)
 
 # Remove the iptables rule
 assert(os.system(IPTABLE_RULE % ('D', SECDEV_IP4)) == 0)
-- 
GitLab