From: Andrew Lewis Date: Wed, 29 Jun 2016 15:43:16 +0000 (+0200) Subject: [Test] Fix Python3 compatibility X-Git-Tag: 1.3.0~214^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F686%2Fhead;p=rspamd.git [Test] Fix Python3 compatibility --- 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)