From a5e447b6dc3605f2d6770e7296913fd8a3a82f9c Mon Sep 17 00:00:00 2001
From: Phil <phil@secdev.org>
Date: Tue, 5 May 2009 00:25:52 +0200
Subject: [PATCH] Wrapped Automaton state methods with objects to give them
 .breaks() and .intercepts() methods

---
 scapy/automaton.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/scapy/automaton.py b/scapy/automaton.py
index 3c500131..84b1ff5b 100644
--- a/scapy/automaton.py
+++ b/scapy/automaton.py
@@ -36,6 +36,21 @@ class Message:
                                          for (k,v) in self.__dict__.iteritems()
                                          if not k.startswith("_"))
 
+class instance_state:
+    def __init__(self, instance):
+        self.im_self = instance.im_self
+        self.im_func = instance.im_func
+        self.im_class = instance.im_class
+    def __getattr__(self, attr):
+        return getattr(self.im_func, attr)
+
+    def __call__(self, *args, **kargs):
+        return self.im_func(self.im_self, *args, **kargs)
+    def breaks(self):
+        return self.im_self.add_breakpoints(self.im_func)
+    def intercepts(self):
+        return self.im_self.add_interception_points(self.im_func)
+        
 
 ##############
 ## Automata ##
@@ -370,6 +385,12 @@ class Automaton:
             ioout.ioname = n
             setattr(self.io, n, self._IO_mixer(ioout,ioin))
             setattr(self.oi, n, self._IO_mixer(ioin,ioout))
+
+            
+        for stname in self.states:
+            setattr(self, stname, 
+                    instance_state(getattr(self, stname)))
+        
         
         self.parse_args(*args, **kargs)
 
-- 
GitLab