@@ -76,11 +76,13 @@ example::
76
76
77
77
The receiver factory is a two-argument callable which is passed the constructed
78
78
sender and the ``ParserProtocol `` instance. The returned object must at least
79
- have ``connectionMade `` and ``connectionLost `` methods. These are called at the
80
- same time as the same-named methods on the ``ParserProtocol ``.
79
+ have ``prepareParsing `` and ``finishParsing `` methods. ``prepareParsing `` is
80
+ called when a connection is established (i.e. in the ``connectionMade `` of the
81
+ ``ParserProtocol ``) and ``finishParsing `` is called when a connection is closed
82
+ (i.e. in the ``connectionLost `` of the ``ParserProtocol ``).
81
83
82
84
.. note ::
83
- Both the receiver factory and its returned object's ``connectionMade `` are
85
+ Both the receiver factory and its returned object's ``prepareParsing `` are
84
86
called at in the ``ParserProtocol ``'s ``connectionMade `` method; this
85
87
separation is for ease of testing receivers.
86
88
@@ -91,10 +93,10 @@ and echos the same netstrings back::
91
93
def __init__(self, sender, parser):
92
94
self.sender = sender
93
95
94
- def connectionMade (self):
96
+ def prepareParsing (self):
95
97
pass
96
98
97
- def connectionLost (self, reason):
99
+ def finishParsing (self, reason):
98
100
pass
99
101
100
102
def netstringReceived(self, string):
@@ -141,10 +143,10 @@ And finally, a complete example::
141
143
def __init__(self, sender, parser):
142
144
self.sender = sender
143
145
144
- def connectionMade (self):
146
+ def prepareParsing (self):
145
147
pass
146
148
147
- def connectionLost (self, reason):
149
+ def finishParsing (self, reason):
148
150
pass
149
151
150
152
def netstringReceived(self, string):
@@ -175,7 +177,7 @@ Intermezzo: error reporting
175
177
If an exception is raised from within Parsley during parsing, whether it's due
176
178
to input not matching the current rule or an exception being raised from code
177
179
the grammar calls, the connection will be immediately closed. The traceback
178
- will be captured as a `Failure `_ and passed to the ``connectionLost `` method of
180
+ will be captured as a `Failure `_ and passed to the ``finishParsing `` method of
179
181
the receiver.
180
182
181
183
At present, there is no way to recover from failure.
@@ -234,10 +236,10 @@ The corresponding receiver and again, constructing the Protocol::
234
236
def __init__(self, sender, parser):
235
237
self.sender = sender
236
238
237
- def connectionMade (self):
239
+ def prepareParsing (self):
238
240
pass
239
241
240
- def connectionLost (self, reason):
242
+ def finishParsing (self, reason):
241
243
pass
242
244
243
245
def netstringFirstHalfReceived(self, string):
@@ -280,7 +282,7 @@ of a receiver for netstrings2::
280
282
self.sender = sender
281
283
self.parser = parser
282
284
283
- def connectionMade (self):
285
+ def prepareParsing (self):
284
286
self.parser.setNextRule('colon')
285
287
286
288
In our case calling ``setNextRule `` is required before parsing begins since
@@ -290,7 +292,7 @@ to match against a nonexistant rule and fail.
290
292
.. note ::
291
293
292
294
It doesn't matter if ``setNextRule `` is called in ``__init__ `` or
293
- ``connectionMade `` to set the starting rule as long as it's called in one of
295
+ ``prepareParsing `` to set the starting rule as long as it's called in one of
294
296
them (or something called by one of them).
295
297
296
298
The other way to change the current rule is to make the current rule evaluate
@@ -318,7 +320,7 @@ The same effect can be achieved with ``setNextRule``::
318
320
319
321
``setNextRule `` can be called at any time. However, if ``setNextRule `` is
320
322
called from somewhere other than the receiver factory, its
321
- ``connectionMade ``, or a method called from the grammar, Parsley will wait
323
+ ``prepareParsing ``, or a method called from the grammar, Parsley will wait
322
324
until the current rule is completely matched before switching rules.
323
325
324
326
0 commit comments