Skip to content
Snippets Groups Projects
Commit 454a3b02 authored by Phil's avatar Phil
Browse files

Added ability to hook packet class creation

Typical use is to register many different kinds of a packet at their
declaration.
parent 631c1627
No related branches found
No related tags found
No related merge requests found
......@@ -150,16 +150,27 @@ class Packet_metaclass(type):
dct["fields_desc"] = final_fld
newcls = super(Packet_metaclass, cls).__new__(cls, name, bases, dct)
if hasattr(newcls,"register_variant"):
newcls.register_variant()
for f in newcls.fields_desc:
f.register_owner(newcls)
config.conf.layers.register(newcls)
return newcls
def __getattr__(self, attr):
for k in self.fields_desc:
if k.name == attr:
return k
raise AttributeError(attr)
def __call__(cls, *args, **kargs):
if "dispatch_hook" in cls.__dict__:
cls = cls.dispatch_hook(*args, **kargs)
i = cls.__new__(cls, cls.__name__, cls.__bases__, cls.__dict__)
i.__init__(*args, **kargs)
return i
class NewDefaultValues(Packet_metaclass):
"""NewDefaultValues is deprecated (not needed anymore)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment