aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-06-29 17:43:16 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-06-29 18:01:26 +0200
commite3a301a85d355a7f559173b88613fb4da5fbd016 (patch)
tree85fdd4b361d65ce7bf53f485cc709bd0e4a0ce3b
parent883800f3912a1a560c4393422e81aac6fa260a3e (diff)
downloadrspamd-e3a301a85d355a7f559173b88613fb4da5fbd016.tar.gz
rspamd-e3a301a85d355a7f559173b88613fb4da5fbd016.zip
[Test] Fix Python3 compatibility
-rw-r--r--test/functional/lib/rspamd.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index 998eb6960..93ec4c430 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -6,9 +6,16 @@ import shutil
import signal
import socket
import string
+import sys
import tempfile
import time
-import urllib2
+
+if sys.version_info > (3,):
+ long = int
+try:
+ from urllib.request import urlopen
+except:
+ from urllib2 import urlopen
def cleanup_temporary_directory(directory):
shutil.rmtree(directory)
@@ -41,9 +48,7 @@ def read_log_from_position(filename, offset):
return [goo, size+offset]
def scan_file(addr, port, filename):
- req = urllib2.Request("http://%s:%s/symbols?%s" % (addr, port, filename))
- response = urllib2.urlopen(req)
- return response.read()
+ return str(urlopen("http://%s:%s/symbols?%s" % (addr, port, filename)).read())
def Send_SIGUSR1(pid):
pid = int(pid)
@@ -56,13 +61,15 @@ def set_directory_ownership(path, username, groupname):
def spamc(addr, port, filename):
goo = open(filename, 'rb').read()
- length = len(goo)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((addr, port))
- s.send("SYMBOLS SPAMC/1.0\r\nContent-length: %s\r\n\r\n%s" % (length, goo))
+ s.send(b"SYMBOLS SPAMC/1.0\r\nContent-length: ")
+ s.send(str(len(goo)).encode('utf-8'))
+ s.send(b"\r\n\r\n")
+ s.send(goo)
s.shutdown(socket.SHUT_WR)
r = s.recv(2048)
- return r
+ return r.decode('utf-8')
def update_dictionary(a, b):
a.update(b)