Package flumotion :: Package component :: Package misc :: Package porter :: Module porter :: Class PorterProtocol
[hide private]

Class PorterProtocol

source code

twisted.internet.protocol.BaseProtocol --+    
                                         |    
        twisted.internet.protocol.Protocol --+
                                             |
                       common.log.Loggable --+
                                             |
                                            PorterProtocol
Known Subclasses:

The base porter is capable of accepting HTTP-like protocols (including RTSP) - it reads the first line of a request, and makes the decision solely on that.

We can't guarantee that we read precisely a line, so the buffer we accumulate will actually be larger than what we actually parse.

Instance Methods [hide private]
 
__init__(self, porter) source code
 
dataReceived(self, data)
Called whenever data is received.
source code
 
parseLine(self, line)
Parse the initial line of the response.
source code
 
writeNotFoundResponse(self)
Write a response indicating that the requested resource was not found in this protocol.
source code

Inherited from twisted.internet.protocol.Protocol: connectionLost

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

Inherited from common.log.Loggable: debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure

Class Variables [hide private]
  MAX_SIZE = 4096
the maximum number of bytes allowed for the first line
  delimiters = ['\r\n', '\n', '\r']
a list of valid line delimiters I check for

Inherited from twisted.internet.protocol.Protocol: __implemented__, __provides__

Inherited from twisted.internet.protocol.BaseProtocol: connected, transport

Inherited from common.log.Loggable: logCategory

Method Details [hide private]

dataReceived(self, data)

source code 

Called whenever data is received.

Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

Parameters:
  • data - a string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
Overrides: twisted.internet.protocol.Protocol.dataReceived
(inherited documentation)

parseLine(self, line)

source code 

Parse the initial line of the response. Return a string usable for uniquely identifying the stream being requested, or None if the request is unreadable.

Subclasses should override this.

writeNotFoundResponse(self)

source code 

Write a response indicating that the requested resource was not found in this protocol.

Subclasses should override this to use the correct protocol.