From d065d97888af6a9c0420cf54cce1f1b0bb0d728d Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Tue, 31 Oct 2006 23:36:59 +0000 Subject: [PATCH] - Use pickle instead of cPickle. Python 2.5 gives an exception with cPickle - Use a binary format instead of ASCII git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@443 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 2 ++ TODO | 2 ++ client/csocket.py | 5 +++-- server/ssocket.py | 6 ++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fe968098..a90baae0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,8 @@ ver. 0.7.4 (2006/??/??) - beta Python - Better debugging output for "fail2ban-regex" - Added support for more date format +- cPickle does not work with Python 2.5. Use pickle instead + (performance is not a problem in our case) ver. 0.7.3 (2006/09/28) - beta ---------- diff --git a/TODO b/TODO index 6b13c144..72101fd0 100644 --- a/TODO +++ b/TODO @@ -13,6 +13,8 @@ Legend: # partially done * done +- Fix the cPickle issue with Python 2.5 + - Multiline log reading - Improve communication. (asyncore, asynchat??) diff --git a/client/csocket.py b/client/csocket.py index 29484622..444792f9 100644 --- a/client/csocket.py +++ b/client/csocket.py @@ -24,7 +24,8 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -from cPickle import dumps, loads +#from cPickle import dumps, loads, HIGHEST_PROTOCOL +from pickle import dumps, loads, HIGHEST_PROTOCOL import socket class CSocket: @@ -40,7 +41,7 @@ class CSocket: def send(self, msg): # Convert every list member to string - obj = dumps(map(str, msg)) + obj = dumps(map(str, msg), HIGHEST_PROTOCOL) self.__csock.send(obj + CSocket.END_STRING) ret = self.receive(self.__csock) self.__csock.close() diff --git a/server/ssocket.py b/server/ssocket.py index 35873879..dfc69fca 100644 --- a/server/ssocket.py +++ b/server/ssocket.py @@ -25,7 +25,9 @@ __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" from threading import Thread -from cPickle import dumps, loads +# cPickle generates an exception with Python 2.5 +#from cPickle import dumps, loads, HIGHEST_PROTOCOL +from pickle import dumps, loads, HIGHEST_PROTOCOL import socket, logging, os, os.path # Gets the instance of the logger. @@ -113,7 +115,7 @@ class SocketWorker(Thread): @staticmethod def __send(sock, msg): - obj = dumps(msg) + obj = dumps(msg, HIGHEST_PROTOCOL) sock.send(obj + SSocket.END_STRING) @staticmethod