Comments like Python comments are supported as well, starting with # and extending to the end of the line.
The Twisted Protocol subclass used for parsing stream protocols using Parsley. It has two public attributes:
After the connection is established, this attribute will refer to the sender created by the sender factory of the ParserProtocol.
After the connection is established, this attribute will refer to the receiver created by the receiver factory of the ParserProtocol.
It’s common to also add a factory attribute to the ParserProtocol from its factory’s buildProtocol method, but this isn’t strictly required or guaranteed to be present.
Subclassing or instantiating ParserProtocol is not necessary; makeProtocol() is sufficient and requires less boilerplate.
Receiver is not a real class but is used here for demonstration purposes to indicate the required API.
ParserProtocol examines the currentRule attribute at the beginning of parsing as well as after every time a rule has completely matched. At these times, the rule with the same name as the value of currentRule will be selected to start parsing the incoming stream of data.
prepareParsing() is called after the ParserProtocol has established a connection, and is passed the ParserProtocol instance itself.
Parameters: | parserProtocol – An instance of ProtocolParser. |
---|
finishParsing() is called if an exception was raised during parsing, or when the ParserProtocol has lost its connection, whichever comes first. It will only be called once.
An exception raised during parsing can be due to incoming data that doesn’t match the current rule or an exception raised calling python code during matching.
Parameters: | reason – A Failure encapsulating the reason parsing has ended. |
---|
Senders do not have any required API as ParserProtocol will never call methods on a sender.