def connect_protocol(self, protocol): t = StringTransport() protocol.makeConnection(t) # ... and let's skip the handshake protocol.dataReceived('.') return t
def test_invalid_port(self): """A request with an invalid port fails with a 400.""" protocol = tunnel_server.ServerTunnelProtocol( tunnel_server.RemoteSocket) protocol.transport = FakeTransport() protocol.dataReceived("CONNECT 127.0.0.1:wrong_port HTTP/1.0" + CRLF * 2) status_line = protocol.transport.getvalue() self.assertTrue(status_line.startswith("HTTP/1.0 400 "), "The port must be an integer.")
def receiveData(self, connection, data): """ Receives some data for the given protocol. """ try: protocol = self._protocols[connection] except KeyError: raise NoSuchConnection() protocol.dataReceived(data) return {}
def testMessages(self): from twisted.mail import protocols protocol = protocols.DomainSMTP() protocol.service = self.factory protocol.factory = self.factory protocol.receivedHeader = spameater protocol.makeConnection(self.transport) protocol.lineReceived('HELO yyy.com') for message in self.messages: protocol.lineReceived('MAIL FROM:<%s>' % message[0]) for target in message[1]: protocol.lineReceived('RCPT TO:<%s>' % target) protocol.lineReceived('DATA') protocol.dataReceived(message[2]) protocol.lineReceived('.') protocol.lineReceived('QUIT') if self.mbox != self.factory.domains['baz.com'].messages: raise AssertionError(self.factory.domains['baz.com'].messages) protocol.setTimeout(None)
def test_clearLineBuffer(self): """ L{LineReceiver.clearLineBuffer} removes all buffered data and returns it as a C{str} and can be called from beneath C{dataReceived}. """ class ClearingReceiver(basic.LineReceiver): def lineReceived(self, line): self.line = line self.rest = self.clearLineBuffer() protocol = ClearingReceiver() protocol.dataReceived('foo\r\nbar\r\nbaz') self.assertEqual(protocol.line, 'foo') self.assertEqual(protocol.rest, 'bar\r\nbaz') # Deliver another line to make sure the previously buffered data is # really gone. protocol.dataReceived('quux\r\n') self.assertEqual(protocol.line, 'quux') self.assertEqual(protocol.rest, '')
def addProtocolFactory(self, deferred, canceller, protocolFactory): if canceller.cancelled: return None protocol = protocolFactory.buildProtocol(self._address) log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Append %(p)s (length: %(l)d+1)', p=protocol, l=len(self._protocols), logLevel=_DEBUG) self._protocols.append(protocol) deferred.callback(protocol) if self.transport is not None: transport = EpicsSubscriptionTransport(self.transport, protocol, self) log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Connected so call makeConnection %(t)s', t=transport, logLevel=_TRACE) protocol.makeConnection(transport) if self._connected: protocol.connectionMade() if self._data is not None: protocol.dataReceived(self._data) else: log.msg('EpicsSubscriptionProtocol: addProtocolFactory: Not connected so do NOT call makeConnection', logLevel=_TRACE) return protocol
def dataReceived(self, data): log.msg('DistributingProtocol: dataReceived: Data type: %(t)s', t=type(data), logLevel=_TRACE) for protocol in self._protocols: log.msg('DistributingProtocol: dataReceived: Distribute to %(p)s', p=protocol, logLevel=_TRACE) protocol.dataReceived(data)