Skip to content

Commit 6904f2e

Browse files
committed
Add docstrings.
1 parent 1eece1f commit 6904f2e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

ometa/protocol.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,47 @@
55

66

77
class ParserProtocol(Protocol):
8+
"""
9+
A Twisted ``Protocol`` subclass for parsing stream protocols.
10+
"""
11+
12+
813
def __init__(self, grammar, senderFactory, receiverFactory, bindings):
14+
"""
15+
Initialize the parser.
16+
17+
:param grammar: An OMeta grammar to use for parsing.
18+
:param senderFactory: A unary callable that returns a sender given a
19+
transport.
20+
:param receiverFactory: A unary callable that returns a receiver given
21+
a sender.
22+
:param bindings: A dict of additional globals for the grammar rules.
23+
"""
24+
925
self.grammar = grammar
1026
self.bindings = dict(bindings)
1127
self.senderFactory = senderFactory
1228
self.receiverFactory = receiverFactory
1329
self.disconnecting = False
1430

1531
def connectionMade(self):
32+
"""
33+
Start parsing, since the connection has been established.
34+
"""
35+
1636
self.sender = self.senderFactory(self.transport)
1737
self.receiver = self.receiverFactory(self.sender)
1838
self.receiver.prepareParsing()
1939
self.parser = TrampolinedParser(
2040
self.grammar, self.receiver, self.bindings)
2141

2242
def dataReceived(self, data):
43+
"""
44+
Receive and parse some data.
45+
46+
:param data: A ``str`` from Twisted.
47+
"""
48+
2349
if self.disconnecting:
2450
return
2551

@@ -31,6 +57,12 @@ def dataReceived(self, data):
3157
return
3258

3359
def connectionLost(self, reason):
60+
"""
61+
Stop parsing, since the connection has been lost.
62+
63+
:param reason: A ``Failure`` instance from Twisted.
64+
"""
65+
3466
if self.disconnecting:
3567
return
3668
self.receiver.finishParsing(reason)

0 commit comments

Comments
 (0)