Package twisted :: Package protocols :: Module basic :: Class LineReceiver

[frames | no frames]

## Class LineReceiver

    BaseProtocol --+
                   |
            Protocol --+
                       |
                      LineReceiver

Known Subclasses:
  `DccChat`, `DictClient`, `FileReceive`, `FileSend`, `Finger`, `FlashConduit`, `FTP`, `FTPClient`, `FTPFileListProtocol`, `HTTPChannel`, `HTTPClient`, `IMAP4Client`, `IMAP4Server`, `IRCClient`, `LineLogger`, `MessagesParser`, `MSNEventBase`, `NMEAReceiver`, `NNTPClient`, `NNTPServer`, `PostfixTCPMapServer`, `SMTP`, `SMTPClient`

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.

Method Summary
| ``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 Protocol
| ``connectionFailed`(self)` (Deprecated)
| ``connectionLost`(self, reason)` Called when the connection is shut down.
Inherited from BaseProtocol
| ``connectionMade`(self)` Called when a connection is made.
| ``makeConnection`(self, transport)` Make a connection to a transport and a server.

Class Variable Summary
`str` | `_LineReceiver__buffer` = `''`
`str` | `delimiter`: The line-ending delimiter to use.
`int` | `line_mode` = 1
`int` | `MAX_LENGTH`: The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped).
Inherited from Protocol
`tuple` | `__implements__` = `(<class twisted.internet.interfaces.IPr...`
Inherited from BaseProtocol
`int` | `connected` = 0
`NoneType` | `transport` = None

Method Details

### clearLineBuffer(self)

Clear buffered data.

### dataReceived(self, data)

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

  Overrides:
    `twisted.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.

### 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.

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.

### setRawMode(self)

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

Class Variable Details

### _LineReceiver__buffer

  Type:
    `str`
  Value:

        ''

### delimiter

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

  Type:
    `str`
  Value:

        '''\r
        '''

### line_mode

  Type:
    `int`
  Value:

        1

### 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.

  Type:
    `int`
  Value:

        16384

Generated by Epydoc 2.0 on Sat May 15 20:08:20 2004 | http://epydoc.sf.net