Exemple #1
0
 def sendLine(self, line):
     # Si la linea ya viene con \r\n, se la quieto por que
     # sendLine se lo agrega.
     if line.endswith('\r\n'):
         line = line[:-2]
     log.msg("=> %s" % line, system=self.get_ccc())
     LineOnlyReceiver.sendLine(self, line)
Exemple #2
0
    def sendLine(self, line):
        """
        Log sent lines.
        """

        log.msg("%s < %r" % (self.sid, line))
        LineOnlyReceiver.sendLine(self, line)
Exemple #3
0
 def connectionLost(self, reason):
     """Clean up and let the superclass handle it."""
     Telnet.connectionLost(self, reason)
     LineOnlyReceiver.connectionLost(self, reason)
     #flush out the buffer
     if self._buffer:
         self.lineReceived(self._buffer)
     self.factory.realm.connectionLost()
Exemple #4
0
 def connectionLost(self, reason):
     """Clean up and let the superclass handle it."""
     Telnet.connectionLost(self, reason)
     LineOnlyReceiver.connectionLost(self, reason)
     #flush out the buffer
     if self._buffer:
         self.lineReceived(self._buffer)
     self.factory.realm.connectionLost()
Exemple #5
0
 def connectionMade(self):
     """Call our superclasses.
     
     Late initialisation should also go here.
     """
     self.factory.realm.connectionMade()
     Telnet.connectionMade(self)
     LineOnlyReceiver.connectionMade(self)
Exemple #6
0
 def connectionMade(self):
     """Call our superclasses.
     
     Late initialisation should also go here.
     """
     
     self.factory.realm.connectionMade()
     Telnet.connectionMade(self)
     LineOnlyReceiver.connectionMade(self)
Exemple #7
0
    def connectionMade(self):
        """
        Notify our factory that we're ready to accept connections.
        """
        LineOnlyReceiver.connectionMade(self)

        self.factory.connectionPool.clientFree(self)

        if self.factory.deferred is not None:
            self.factory.deferred.callback(self)
            self.factory.deferred = None
Exemple #8
0
def bytesDelimitedBy(delimiter):
    """
    Consumes a stream of bytes and produces frames delimited by the given
    delimiter.

    @param delimiter: an octet sequence that separates frames in the incoming
        stream of bytes.
    @type delimiter: L{bytes}

    @return: a tube that converts a stream of bytes into a sequence of frames.
    @rtype: L{ITube}
    """
    receiver = LineOnlyReceiver()
    receiver.delimiter = delimiter
    return _SegmentsToFrames(receiver, "lineReceived")
Exemple #9
0
def bytesDelimitedBy(delimiter):
    """
    Consumes a stream of bytes and produces frames delimited by the given
    delimiter.

    @param delimiter: an octet sequence that separates frames in the incoming
        stream of bytes.
    @type delimiter: L{bytes}

    @return: a tube that converts a stream of bytes into a sequence of frames.
    @rtype: L{ITube}
    """
    receiver = LineOnlyReceiver()
    receiver.delimiter = delimiter
    return _SegmentsToFrames(receiver, "lineReceived")
Exemple #10
0
    def sendLine(self, line):
        """
        Override sendLine method
        """

        if not self._current:
            self.setTimeout(self.persistentTimeOut)

        if not isinstance(line, str):
            return fail(
                ClientError("Invalid type for value: %s, expecting a string" %
                            (type(line), )))
        LineOnlyReceiver.sendLine(self, line)
        cmdObj = Command(line)
        self._current.append(cmdObj)
        return cmdObj._deferred
Exemple #11
0
    def dataReceived(self, data: bytes):
        self._buffer += data

        # something weird to do with the brainboxes?
        if self._buffer[:9] == b'\xff\xfd\x03\xff\xfd\x00\xff\xfd,':
            self._buffer = self._buffer[9:]

        return LineOnlyReceiver.dataReceived(self, b"")
Exemple #12
0
	def dataReceived (self, data):
		self._buffer += data

		# something weird to do with the brainboxes?
		if self._buffer[:9] == '\xff\xfd\x03\xff\xfd\x00\xff\xfd,':
			self._buffer = self._buffer[9:]

		return LineOnlyReceiver.dataReceived(self, "")
Exemple #13
0
 def connectionLost(self,reason):
     print(self)
     if reason.check(twisted.internet.error.ConnectionDone):
         print('%s: connection closed.' % self.name)
     else:
         print('%s: connection lost: %s' % (self.name,reason))
     self.connectedSince = None
     return Receiver.connectionLost(self,reason)
Exemple #14
0
def linesToBytes():
    """
    Convert lines into bytes.

    @return: Create a new tube for adding CRLF delimiters to a sequence of
        lines (frames) to produce bytes (segments).
    """
    return _FramesToSegments(LineOnlyReceiver(), "sendLine")
Exemple #15
0
 def connectionLost(self, reason):
     print(self)
     if reason.check(twisted.internet.error.ConnectionDone):
         print('%s: connection closed.' % self.name)
     else:
         print('%s: connection lost: %s' % (self.name, reason))
     self.connectedSince = None
     return Receiver.connectionLost(self, reason)
Exemple #16
0
    def dataReceived(self, data):
        """
        Overridden to stop trying to read data while outputting a response.

        This stops netcat from quitting before it gets the output!
        """
        reactor.removeReader(self.reader)
        retval = LineOnlyReceiver.dataReceived(self, data)
        reactor.getThreadPool().callInThreadWithCallback(
            self.processLinesDone, self.processLines)
        return retval
Exemple #17
0
    def dataReceived(self, data):
        """
        Overridden to stop trying to read data while outputting a response.

        This stops netcat from quitting before it gets the output!
        """
        reactor.removeReader(self.reader)
        retval = LineOnlyReceiver.dataReceived(self, data)
        reactor.getThreadPool().callInThreadWithCallback(
            self.processLinesDone, self.processLines)
        return retval
Exemple #18
0
 def connectionLost(self, reason):
     """When TCP connection is lost, remove shutdown handler
     """
     if reason.type == ConnectionLost:
         msg = 'Disconnected'
     else:
         msg = 'Disconnected: %s' % reason.getErrorMessage()
     self.log.debug(msg)
         
     #Remove connect timeout if set
     if self.connectTimeoutDelayedCall is not None:
         self.log.debug("Cancelling connect timeout after TCP connection was lost")
         self.connectTimeoutDelayedCall.cancel()
         self.connectTimeoutDelayedCall = None
     
     #Callback for failed connect
     if self.connectedDeferred:
         if self.connectError:
             self.log.debug("Calling connectedDeferred errback: %s" % self.connectError)
             self.connectedDeferred.errback(self.connectError)
             self.connectError = None
         else:
             self.log.error("Connection lost with outstanding connectedDeferred")
             error = StompError("Unexpected connection loss")
             self.log.debug("Calling connectedDeferred errback: %s" % error)
             self.connectedDeferred.errback(error)                
         self.connectedDeferred = None
     
     #Callback for disconnect
     if self.disconnectedDeferred:
         if self.disconnectError:
             #self.log.debug("Calling disconnectedDeferred errback: %s" % self.disconnectError)
             self.disconnectedDeferred.errback(self.disconnectError)
             self.disconnectError = None
         else:
             #self.log.debug("Calling disconnectedDeferred callback")
             self.disconnectedDeferred.callback(self)
         self.disconnectedDeferred = None
         
     LineOnlyReceiver.connectionLost(self, reason)
Exemple #19
0
 def connectionMade(self):
     """When TCP connection is made, register shutdown handler
     """
     LineOnlyReceiver.connectionMade(self)
Exemple #20
0
 def connectionMade(self):
     LineOnlyReceiver.connectionMade(self)
     self.started = False
     self.lines = []
     self.pendingActions = {}
Exemple #21
0
 def lineLengthExceeded(self, message):
     print('%s: max line length exceeded: %d > %d' %
           (self.name, len(message), self.MAX_LENGTH))
     return Receiver.lineLengthExceeded(self, message)
Exemple #22
0
 def sendLine(self, line):
     line = line.replace("\r", "").replace("\n", "")
     if self.showirc:
         LOG.log(5, "<: %s" % line)
     LineOnlyReceiver.sendLine(self, line)
Exemple #23
0
 def dataReceived(self, data):
     LineOnlyReceiver.dataReceived(self, data)
     self.timeout_handler.refresh()
Exemple #24
0
 def sendLine(self, line):
     self.log.trace("-> %s" % repr(line))
     LineOnlyReceiver.sendLine(self, line)
Exemple #25
0
 def lineLengthExceeded(self, line):
     LineOnlyReceiver.lineLengthExceeded(self, line)
Exemple #26
0
 def connectionMade(self):
     LineOnlyReceiver.connectionMade(self)
     self.started = False
     self.lines = []
     self.pendingActions = {}
Exemple #27
0
 def connectionMade(self):
     self.connectedSince = datetime.now()
     print('%s: connected to %s' % (self.name, self.transport.getPeer()))
     return Receiver.connectionMade(self)
Exemple #28
0
 def sendLine(self, line):
     line = line.replace('\r', '').replace('\n', '')
     if self.showirc:
         LOG.log(5, "<: %s" % line)
     LineOnlyReceiver.sendLine(self, line)
Exemple #29
0
 def sendLine(self, line):
     #print "<:", line
     LineOnlyReceiver.sendLine(self, line.replace('|','&#124;'))
 def sendLine(self, line):
     print 'S: ' + line
     print "Enviar?"
     raw_input()
     LineOnlyReceiver.sendLine(self, line)
Exemple #31
0
 def connectionMade(self):
     "Start the timeout once the connection has been established."
     self.setTimeout(self.timeoutPeriod)
     LineOnlyReceiver.connectionMade(self)
 def sendLine(self, line):
     if not isinstance(line, str):
         line = str(line)
     LineOnlyReceiver.sendLine(self, line)
Exemple #33
0
 def dataReceived(self, data):
     "Reset the timeout and parse the received data."
     self.resetTimeout()
     LineOnlyReceiver.dataReceived(self, data)
Exemple #34
0
 def sendLine(self, line):
     line = line.replace('\r', '').replace('\n', '')
     if self.showirc:
         LOG.log(5, "<: %s" % line)
     LineOnlyReceiver.sendLine(self, line)
Exemple #35
0
 def sendLine(self, line):
     LineOnlyReceiver.sendLine(self, str(line))
Exemple #36
0
 def sendLine(self, line):
     #print "<:", line
     LineOnlyReceiver.sendLine(self, line.replace('|', '&#124;'))
 def sendLine(self, line):
     print 'S: ' + line
     if not self.saludo: LineOnlyReceiver.sendLine(self, line)        # Saludo y nada m?s para no hacer tanto ruido
Exemple #38
0
 def sendLine(self, line): # overrides twisted function
     peer = self.transport.getPeer()
     logging.debug("Sending line '{}' to {}:{}:{}".format(line, peer.type, peer.host, peer.port))
     return LineOnlyReceiver.sendLine(self, line)
Exemple #39
0
 def sendLine(self, line):
     self.log.trace("-> %s" % repr(line))
     LineOnlyReceiver.sendLine(self, line)
Exemple #40
0
 def lineLengthExceeded(self, line): # overrides twisted function
     peer = self.transport.getPeer()
     logging.warning("Incomming line of length {} exceeded MAX_LENGTH of {}, dropping unvalidated connection to {}:{}:{}".format(len(line), self.MAX_LENGTH, peer.type, peer.host, peer.port))
     return LineOnlyReceiver.lineLengthExceeded(self, line)
 def dataReceived(self, data):
     LineOnlyReceiver.dataReceived(self, data)
Exemple #42
0
 def connectionMade(self):
     logger.debug('<TelegrafProtocol.connectionMade> %s', self)
     self.closed_d = Deferred()
     self.connected = 1
     LineOnlyReceiver.connectionMade(self)
Exemple #43
0
 def connectionMade(self):
     self.connectedSince = datetime.now()
     print('%s: connected to %s' % (self.name,self.transport.getPeer()))
     return Receiver.connectionMade(self)
Exemple #44
0
 def connectionLost(self, reason):
     self.connected = 0
     self.closed_d.callback(0)
     logger.debug('<TelegrafProtocol.connectionLost> %s %s', reason, self)
     LineOnlyReceiver.connectionLost(self)
Exemple #45
0
 def lineLengthExceeded(self,message):
     print('%s: max line length exceeded: %d > %d' % (
         self.name,len(message),self.MAX_LENGTH
     ))
     return Receiver.lineLengthExceeded(self,message)
Exemple #46
0
 def dataReceived(self, data):
     LineOnlyReceiver.dataReceived(self, data)
     self.timeout_handler.refresh()