From 3f9a902198dce92f9044f22f34a1b89ab618e29e Mon Sep 17 00:00:00 2001 From: Yuichi Ito Date: Thu, 12 Dec 2013 15:30:56 +0900 Subject: packet lib: packet_base: add a method which makes '_class_prefixes' easy to use the variable '_class_prefixes' of stringify.StringifyMixin is used to help the method 'from_jsondict()' to create the class instance. '_class_prefixes' requires a list of the class names. some classes have another list of the class names already. this patch adds a method which makes '_class_prefixes' by using the existing list. before applying this patch: (e.g. ryu.lib.packet.ipv6) # append the name to another list @ipv6.register_header_type(inet.IPPROTO_HOPOPTS) class hop_opts(opt_header): ... @ipv6.register_header_type(inet.IPPROTO_DSTOPTS) class dst_opts(opt_header): .... # append the name again ipv6._class_prefixes = ['hop_opts', 'dst_opts', ...] after applying this patch: (e.g. ryu.lib.packet.ipv6) # append the name to another list @ipv6.register_header_type(inet.IPPROTO_HOPOPTS) class hop_opts(opt_header): ... @ipv6.register_header_type(inet.IPPROTO_DSTOPTS) class dst_opts(opt_header): .... # create the new list from another list ipv6.set_classes(ipv6._IPV6_EXT_HEADER_TYPE) Signed-off-by: Yuichi Ito Signed-off-by: FUJITA Tomonori --- ryu/lib/stringify.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py index 4d56a950..ad771db9 100644 --- a/ryu/lib/stringify.py +++ b/ryu/lib/stringify.py @@ -298,6 +298,11 @@ class StringifyMixin(object): print "KWARG", kwargs raise + @classmethod + def set_classes(cls, registered_dict): + cls._class_prefixes.extend([v.__name__ for v in + registered_dict.values()]) + def obj_python_attrs(msg_): """iterate object attributes for stringify purposes -- cgit v1.2.3