[asterisk-commits] mmichelson: branch group/rls-tests r5316 - /asterisk/team/group/rls-tests/lib...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 25 17:30:27 CDT 2014


Author: mmichelson
Date: Fri Jul 25 17:30:22 2014
New Revision: 5316

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5316
Log:
Fix deficiencies in the pcap library for doing RLS tests.

Full credit to Jonathan Rose for creating this diff.


Modified:
    asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py

Modified: asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py?view=diff&rev=5316&r1=5315&r2=5316
==============================================================================
--- asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py (original)
+++ asterisk/team/group/rls-tests/lib/python/asterisk/pcap.py Fri Jul 25 17:30:22 2014
@@ -29,6 +29,7 @@
 
 LOGGER = logging.getLogger(__name__)
 
+
 class PcapListener(object):
     '''
     A class that creates a pcap file from a test and optionally provides
@@ -74,6 +75,7 @@
         ''' Function that can be overridden by derived classes to inspect
         packets as they arrive from the listener '''
         pass
+
 
 class Packet():
     ''' Some IP packet. Base class for everything else '''
@@ -206,9 +208,11 @@
 class PIDFPacket(Packet):
     '''A PIDF presence body. Owned by SIPPacket or a MultipartPacket.'''
 
-    def __init__(self, ascii_packet, raw_packet):
+    def __init__(self, ascii_packet, raw_packet, content_id):
         Packet.__init__(self, packet_type="PIDF", raw_packet=raw_packet)
         self.xml = ascii_packet.strip()
+
+        self.content_id = content_id
 
 
 class RLMIPacket(Packet):
@@ -234,7 +238,7 @@
         content_type = self.headers.get('Content-Type')
         self.content_id = self.headers.get('Content-ID').strip('<>')
         self.body = BodyFactory.create_body(content_type, body.strip(),
-                                            raw_packet)
+                                            raw_packet, self.content_id)
 
 
 class MultipartPacket(Packet):
@@ -267,7 +271,7 @@
 
 class BodyFactory(object):
     @staticmethod
-    def create_body(content_type, ascii_packet, raw_packet):
+    def create_body(content_type, ascii_packet, raw_packet, content_id=None):
         body_type, _, _ = content_type.partition(';')
         if (body_type == 'application/sdp'):
             return SDPPacket(ascii_packet, raw_packet)
@@ -276,7 +280,7 @@
         elif (body_type == 'application/rlmi+xml'):
             return RLMIPacket(ascii_packet, raw_packet)
         elif (body_type == 'application/pidf+xml'):
-            return PIDFPacket(ascii_packet, raw_packet)
+            return PIDFPacket(ascii_packet, raw_packet, content_id)
         else:
             return Packet(body_type, raw_packet)
     pass
@@ -483,7 +487,7 @@
             except:
                 pass
             if interpreted_packet is not None:
-                break;
+                break
         return interpreted_packet
 
 
@@ -529,10 +533,12 @@
         for callback in self._callbacks[packet.packet_type]:
             callback(packet)
 
-
     def add_callback(self, packet_type, callback):
         ''' Add a callback function for when a packet of a particular type
         is received '''
         if packet_type not in self._callbacks:
             self._callbacks[packet_type] = []
         self._callbacks[packet_type].append(callback)
+
+    def remove_callbacks(self, packet_type):
+        del self._callbacks[packet_type]




More information about the asterisk-commits mailing list