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 --+
                                             |
                   extern.log.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
 
connectionMade(self)
Called when a connection is made.
source code
 
_timeout(self) source code
 
connectionLost(self, reason)
Called when the connection is shut down.
source code
 
dataReceived(self, data)
Called whenever data is received.
source code
 
parseLine(self, line)
Parse the initial line of the request.
source code
 
unparseLine(self, parsed)
Recreate the initial request line from the parsed representation.
source code
 
extractIdentifier(self, parsed)
Extract a string that uniquely identifies the requested stream from the parsed representation of the first request line.
source code
 
generateRequestId(self)
Return a string that will uniquely identify the request.
source code
 
injectRequestId(self, parsed, requestId)
Take the parsed representation of the first request line and a string token, return a parsed representation of the request line with the request-id possibly mixed into it.
source code
 
writeNotFoundResponse(self)
Write a response indicating that the requested resource was not found in this protocol.
source code
 
writeServiceUnavailableResponse(self)
Write a response indicating that the requested resource was temporarily uavailable in this protocol.
source code

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

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

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

Class Variables [hide private]
  logCategory = 'porterprotocol'
Implementors can provide a category to log their messages under.
  MAX_SIZE = 4096
the maximum number of bytes allowed for the first line
  PORTER_CLIENT_TIMEOUT = 30
  delimiters = ['\r\n', '\n', '\r']
a list of valid line delimiters I check for

Inherited from twisted.internet.protocol.Protocol: __implemented__

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

Method Details [hide private]

connectionMade(self)

source code 

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

Overrides: twisted.internet.protocol.BaseProtocol.connectionMade
(inherited documentation)

connectionLost(self, reason)

source code 

Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

Overrides: twisted.internet.protocol.Protocol.connectionLost
(inherited documentation)

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 request. Return an object that can be used to uniquely identify the stream being requested by passing it to extractIdentifier, or None if the request is unreadable.

Subclasses should override this.

unparseLine(self, parsed)

source code 

Recreate the initial request line from the parsed representation. The recreated line does not need to be exactly identical, but both parsedLine(unparseLine(line)) and line should contain the same information (i.e. unparseLine should not lose information).

UnparseLine has to return a valid line from the porter protocol's scheme point of view (for instance, HTTP).

Subclasses should override this.

extractIdentifier(self, parsed)

source code 

Extract a string that uniquely identifies the requested stream from the parsed representation of the first request line.

Subclasses should override this, depending on how they implemented parseLine.

generateRequestId(self)

source code 

Return a string that will uniquely identify the request.

Subclasses should override this if they want to use request-ids and also implement injectRequestId.

injectRequestId(self, parsed, requestId)

source code 

Take the parsed representation of the first request line and a string token, return a parsed representation of the request line with the request-id possibly mixed into it.

Subclasses should override this if they generate request-ids.

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.

writeServiceUnavailableResponse(self)

source code 

Write a response indicating that the requested resource was temporarily uavailable in this protocol.

Subclasses should override this to use the correct protocol.