Ticket #4021: 4021_address_eventTransport.patch

File 4021_address_eventTransport.patch, 7.2 KB (added by jasonjwwilliams, 4 years ago)

Changed portNumber to generic address on log messages in format "host:port" & added eventTransport field.

  • twisted/internet/protocol.py

    diff --git a/twisted/internet/protocol.py b/twisted/internet/protocol.py
    index d7973ca..0eda004 100644
    a b class AbstractDatagramProtocol: 
    622622        This will be called by makeConnection(), users should not call it. 
    623623        """ 
    624624        if not self.numPorts: 
    625             log.msg(eventSource=self, eventType="start", eventTransport="udp", 
    626                     address="", protocol=self) 
     625            log.msg(eventSource=self, eventType="start", protocol=self) 
    627626            self.startProtocol() 
    628627        self.numPorts = self.numPorts + 1 
    629628 
    class AbstractDatagramProtocol: 
    637636        self.numPorts = self.numPorts - 1 
    638637        self.transport = None 
    639638        if not self.numPorts: 
    640             log.msg(eventSource=self, eventType="stop", eventTransport="udp", 
    641                     address="", protocol=self) 
     639            log.msg(eventSource=self, eventType="stop", protocol=self) 
    642640            self.stopProtocol() 
    643641 
    644642 
  • twisted/internet/tcp.py

    diff --git a/twisted/internet/tcp.py b/twisted/internet/tcp.py
    index 0df7d6f..44cb5f9 100644
    a b class Port(base.BasePort, _SocketCloser): 
    859859        # Make sure that if we listened on port 0, we update that to 
    860860        # reflect what the OS actually assigned us. 
    861861        self._realPortNumber = skt.getsockname()[1] 
    862          
    863         _ip = self.interface if self.interface else "0.0.0.0" 
    864862 
    865         log.msg(eventSource=self, eventType="start", eventTransport="tcp", 
    866                 factory=self.factory, 
    867                 address="%s:%d" % (_ip,self._realPortNumber)) 
     863        log.msg(eventSource=self, eventType="start", factory=self.factory, 
     864                portNumber=self._realPortNumber) 
    868865 
    869866        # The order of the next 6 lines is kind of bizarre.  If no one 
    870867        # can explain it, perhaps we should re-arrange them. 
    class Port(base.BasePort, _SocketCloser): 
    979976        """ 
    980977        Log message for closing port 
    981978        """ 
    982         _ip = self.interface if self.interface else "0.0.0.0" 
    983         log.msg(eventSource=self, eventType="stop", eventTransport="tcp", 
    984                 factory=self.factory, 
    985                 address="%s:%d" % (_ip,self._realPortNumber)) 
     979        log.msg(eventSource=self, eventType="stop", factory=self.factory, 
     980                portNumber=self._realPortNumber) 
    986981 
    987982 
    988983    def connectionLost(self, reason): 
  • twisted/internet/test/test_protocol.py

    diff --git a/twisted/internet/test/test_protocol.py b/twisted/internet/test/test_protocol.py
    index 780533b..726f02e 100644
    a b class AbstractDatagramProtocolTestCase(TestCase, DictSubsetMixin): 
    360360            self.events[0], 
    361361            {"eventSource": self.proto, 
    362362             "protocol": self.proto, 
    363              "eventType": "start", 
    364              "eventTransport" : "udp", 
    365              "address" : ""}) 
     363             "eventType": "start"}) 
    366364 
    367365 
    368366    def test_doStopLogMessage(self): 
    class AbstractDatagramProtocolTestCase(TestCase, DictSubsetMixin): 
    377375            self.events[0], 
    378376            {"eventSource": self.proto, 
    379377             "protocol": self.proto, 
    380              "eventType": "stop", 
    381              "eventTransport" : "udp", 
    382              "address" : ""}) 
     378             "eventType": "stop"}) 
  • twisted/internet/test/test_tcp.py

    diff --git a/twisted/internet/test/test_tcp.py b/twisted/internet/test/test_tcp.py
    index 00ffaf8..3497b0a 100644
    a b class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    325325        ReactorBuilder.setUp(self) 
    326326        self.factory = ServerFactory() 
    327327        self.events = [] 
    328         self.transportType = "tcp" 
    329328        log.addObserver(self.events.append) 
    330329        self.addCleanup(log.removeObserver, self.events.append) 
    331330 
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    342341        Get the expected port number for the TCP port that experienced 
    343342        the connection event. 
    344343        """ 
    345         return str(port.getHost().port) 
    346          
    347     def getExpectedConnectionPortHost(self, port): 
    348         """ 
    349         Get the expected hostname/IP for the TCP port that experienced 
    350         the connection event. 
    351         """ 
    352         return port.getHost().host 
     344        return port.getHost().port 
    353345 
    354346 
    355347    def test_portStartStopLogMessage(self): 
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    361353        reactor = self.buildReactor() 
    362354        p = self.getListeningPort(reactor) 
    363355        listenPort = self.getExpectedConnectionPortNumber(p) 
    364         listenHost = self.getExpectedConnectionPortHost(p) 
    365356 
    366357        def stopReactor(ignored): 
    367358            reactor.stop() 
    class TCPPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin, 
    373364        self.runReactor(reactor) 
    374365 
    375366        expected = { 
    376             "eventSource": p, "address": "%s:%s" % (listenHost, listenPort), 
    377             "eventTransport" : self.transportType, "factory": self.factory} 
     367            "eventSource": p, "portNumber": listenPort, "factory": self.factory} 
    378368 
    379369        for event in self.events: 
    380370            if event.get("eventType") == "start": 
  • twisted/internet/test/test_unix.py

    diff --git a/twisted/internet/test/test_unix.py b/twisted/internet/test/test_unix.py
    index 7a3040a..293e965 100644
    a b class UNIXPortTestsBuilder(TCPPortTestsBuilder): 
    147147    """ 
    148148 
    149149    requiredInterfaces = [interfaces.IReactorUNIX] 
    150      
    151     def setUp(self): 
    152         """ 
    153         Extend TCP test setUp to set transportType to 'unix'. 
    154         """ 
    155         TCPPortTestsBuilder.setUp(self) 
    156         self.transportType = "unix" 
    157150 
    158151    def getListeningPort(self, reactor): 
    159152        """ 
    class UNIXPortTestsBuilder(TCPPortTestsBuilder): 
    167160        Get the expected UNIX socket path from the given UNIX listening port. 
    168161        """ 
    169162        return port.getHost().name 
    170      
    171     def getExpectedConnectionPortHost(self, port): 
    172         """ 
    173         Return an empty string, since there is no hostname for a UNIX socket. 
    174         """ 
    175          
    176         return "" 
    177163 
    178164 
    179165globals().update(UNIXTestsBuilder.makeTestCaseClasses()) 
  • twisted/internet/unix.py

    diff --git a/twisted/internet/unix.py b/twisted/internet/unix.py
    index c84f548..1cfe8cd 100644
    a b class Port(_UNIXPort, tcp.Port): 
    112112                    except: 
    113113                        pass 
    114114 
    115         log.msg(eventSource=self, eventType="start", eventTransport="unix", 
    116                 address=":%s" % self.port,factory=self.factory) 
     115        log.msg(eventSource=self, eventType="start", factory=self.factory, 
     116                portNumber=self.port) 
    117117        self.factory.doStart() 
    118118        try: 
    119119            skt = self.createInternetSocket() 
    class Port(_UNIXPort, tcp.Port): 
    136136        """ 
    137137        Log message for closing socket 
    138138        """ 
    139         log.msg(eventSource=self, eventType="stop", eventTransport="unix", 
    140                 address=":%s" % self.port, factory=self.factory) 
     139        log.msg(eventSource=self, eventType="stop", factory=self.factory, 
     140                portNumber=self.port) 
    141141 
    142142 
    143143    def connectionLost(self, reason):