[ovs-dev] [PATCH] stream.py: Don't use class decorators.

Isaku Yamahata yamahata at valinux.co.jp
Wed Oct 17 18:18:16 UTC 2012


On Thu, Oct 18, 2012 at 03:09:02AM +0900, Isaku Yamahata wrote:
> Hi. The patch looks reasonable.
> 
> If it isn't used as decorator, returning class is not necessary.
> I'll send a patch to fix it.

Here's the incremental patch to c38f8724aeb994fd840fa4283a07e38c3c114d68

>From 02683397771860a32d5be4705e92ef88e022709c Mon Sep 17 00:00:00 2001
Message-Id: <02683397771860a32d5be4705e92ef88e022709c.1350497806.git.yamahata at valinux.co.jp>
From: Isaku Yamahata <yamahata at valinux.co.jp>
Date: Thu, 18 Oct 2012 03:13:52 +0900
Subject: [PATCH] stream.py: un-decorator Stream.register_method

c38f8724aeb994fd840fa4283a07e38c3c114d68 made stream.py not use class
decorator. So Stream.register need not to be decorator any more.
So simplify it.

Signed-off-by: Isaku Yamahata <yamahata at valinux.co.jp>
---
 python/ovs/stream.py |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/python/ovs/stream.py b/python/ovs/stream.py
index 6bd0ccb..dad6848 100644
--- a/python/ovs/stream.py
+++ b/python/ovs/stream.py
@@ -54,11 +54,8 @@ class Stream(object):
     _SOCKET_METHODS = {}
 
     @staticmethod
-    def register_method(method):
-        def _register_method(cls):
-            Stream._SOCKET_METHODS[method + ":"] = cls
-            return cls
-        return _register_method
+    def register_method(method, cls):
+        Stream._SOCKET_METHODS[method + ":"] = cls
 
     @staticmethod
     def _find_method(name):
@@ -350,7 +347,7 @@ class UnixStream(Stream):
         connect_path = suffix
         return  ovs.socket_util.make_unix_socket(socket.SOCK_STREAM,
                                                  True, None, connect_path)
-UnixStream = Stream.register_method("unix")(UnixStream)
+Stream.register_method("unix", UnixStream)
 
 
 class TCPStream(Stream):
@@ -361,4 +358,4 @@ class TCPStream(Stream):
         if not error:
             sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
         return error, sock
-TCPStream = Stream.register_method("tcp")(TCPStream)
+Stream.register_method("tcp", TCPStream)
-- 
1.7.10.4



-- 
yamahata



More information about the dev mailing list