twisted :: protocols :: basic :: LineReceiver :: Class LineReceiver
[hide private]
[frames] | no frames]

Class LineReceiver



internet.protocol.BaseProtocol --+    
                                 |    
        internet.protocol.Protocol --+
                                     |
                   _PauseableMixin --+
                                     |
                                    LineReceiver

A protocol that receives lines and/or raw data, depending on mode.

In line mode, each line that's received becomes a callback to lineReceived. In raw data mode, each chunk of raw data becomes a callback to rawDataReceived. The setLineMode and setRawMode methods switch between the two modes.

This is useful for line-oriented protocols such as IRC, HTTP, POP, etc.

Instance Methods [hide private]
 
clearLineBuffer(self)
Clear buffered data.
 
dataReceived(self, data)
Protocol.dataReceived.
 
lineLengthExceeded(self, line)
Called when the maximum line length has been reached.
 
lineReceived(self, line)
Override this for when each line is received.
 
rawDataReceived(self, data)
Override this for when raw data is received.
 
sendLine(self, line)
Sends a line to the other end of the connection.
 
setLineMode(self, extra='')
Sets the line-mode of this receiver.
 
setRawMode(self)
Sets the raw mode of this receiver.

Inherited from internet.protocol.Protocol: connectionLost

Inherited from internet.protocol.BaseProtocol: __providedBy__, connectionMade, makeConnection

Inherited from _PauseableMixin: pauseProducing, resumeProducing, stopProducing

Class Variables [hide private]
  MAX_LENGTH = 16384
The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped).
  __buffer = ''
  delimiter = '\r\n'
The line-ending delimiter to use.
  line_mode = 1

Inherited from internet.protocol.Protocol: __implemented__, __provides__

Inherited from internet.protocol.BaseProtocol: connected, transport

Inherited from _PauseableMixin: paused

Method Details [hide private]

dataReceived(self, data)

 
Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Overrides: internet.protocol.Protocol.dataReceived

lineLengthExceeded(self, line)

 

Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.

The argument 'line' contains the remainder of the buffer, starting with (at least some part) of the line which is too long. This may be more than one line, or may be only the initial portion of the line.

setLineMode(self, extra='')

 

Sets the line-mode of this receiver.

If you are calling this from a rawDataReceived callback, you can pass in extra unhandled data, and that data will be parsed for lines. Further data received will be sent to lineReceived rather than rawDataReceived.

Do not pass extra data if calling this function from within a lineReceived callback.

setRawMode(self)

 
Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.

Class Variable Details [hide private]

MAX_LENGTH

The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped). Default is 16384.
Value:
16384

delimiter

The line-ending delimiter to use. By default this is '\r\n'.
Value:
'''\r
'''