[Neo-report] r2681 jm - in /trunk/neo/lib: __init__.py protocol.py python.py util.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Mar 22 11:27:16 CET 2011
Author: jm
Date: Tue Mar 22 11:27:15 2011
New Revision: 2681
Log:
Move some compatibility code for Python 2.4 into a single place
Added:
trunk/neo/lib/python.py
Modified:
trunk/neo/lib/__init__.py
trunk/neo/lib/protocol.py
trunk/neo/lib/util.py
Modified: trunk/neo/lib/__init__.py
==============================================================================
--- trunk/neo/lib/__init__.py [iso-8859-1] (original)
+++ trunk/neo/lib/__init__.py [iso-8859-1] Tue Mar 22 11:27:15 2011
@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+import neo.lib.python
import logging as logging_std
PREFIX = '%(asctime)s %(levelname)-9s %(name)-10s'
Modified: trunk/neo/lib/protocol.py
==============================================================================
--- trunk/neo/lib/protocol.py [iso-8859-1] (original)
+++ trunk/neo/lib/protocol.py [iso-8859-1] Tue Mar 22 11:27:15 2011
@@ -21,8 +21,9 @@ import traceback
from types import ClassType
from socket import inet_ntoa, inet_aton
from cStringIO import StringIO
+from struct import Struct
-from neo.lib.util import Enum, Struct, getAddressType
+from neo.lib.util import Enum, getAddressType
# The protocol version (major, minor).
PROTOCOL_VERSION = (4, 1)
Added: trunk/neo/lib/python.py
==============================================================================
--- trunk/neo/lib/python.py (added)
+++ trunk/neo/lib/python.py [iso-8859-1] Tue Mar 22 11:27:15 2011
@@ -0,0 +1,70 @@
+# Copyright (C) 2011 Nexedi SA
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+import sys, types
+
+if sys.version_info < (2, 5):
+ import __builtin__, imp
+
+ def all(iterable):
+ """
+ Return True if bool(x) is True for all values x in the iterable.
+ """
+ for x in iterable:
+ if not x:
+ return False
+ return True
+ __builtin__.all = all
+
+ def any(iterable):
+ """
+ Return True if bool(x) is True for any x in the iterable.
+ """
+ for x in iterable:
+ if x:
+ return True
+ return False
+ __builtin__.any = any
+
+ import struct
+
+ class Struct(object):
+
+ def __init__(self, fmt):
+ self._fmt = fmt
+ self.size = struct.calcsize(fmt)
+
+ def pack(self, *args):
+ return struct.pack(self._fmt, *args)
+
+ def unpack(self, *args):
+ return struct.unpack(self._fmt, *args)
+
+ struct.Struct = Struct
+
+ sys.modules['functools'] = functools = imp.new_module('functools')
+
+ def wraps(wrapped):
+ """Simple backport of functools.wraps from Python >= 2.5"""
+ def decorator(wrapper):
+ wrapper.__module__ = wrapped.__module__
+ wrapper.__name__ = wrapped.__name__
+ wrapper.__doc__ = wrapped.__doc__
+ wrapper.__dict__.update(wrapped.__dict__)
+ return wrapper
+ return decorator
+
+ functools.wraps = wraps
Modified: trunk/neo/lib/util.py
==============================================================================
--- trunk/neo/lib/util.py [iso-8859-1] (original)
+++ trunk/neo/lib/util.py [iso-8859-1] Tue Mar 22 11:27:15 2011
@@ -27,23 +27,6 @@ SOCKET_CONNECTORS_DICT = {
socket.AF_INET6: 'SocketConnectorIPv6',
}
-try:
- from struct import Struct
-except ImportError:
- import struct
- # support for python 2.4
- class Struct(object):
-
- def __init__(self, fmt):
- self._fmt = fmt
- self.size = struct.calcsize(fmt)
-
- def pack(self, *args):
- return struct.pack(self._fmt, *args)
-
- def unpack(self, *args):
- return struct.unpack(self._fmt, *args)
-
def u64(s):
return unpack('!Q', s)[0]
More information about the Neo-report
mailing list