1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from twisted.protocols import basic
17 from zope.interface import implements
18 from twisted.internet.interfaces import IAddress, ITransport
19
21 "an address for NullTransport"
22 implements(IAddress)
23
25 "a do-nothing transport to make NetstringReceiver happy"
26 implements(ITransport)
27 - def write(self, data): raise NotImplementedError
34
36 """
37 Adapts the Twisted netstring support (which assumes it is on a socket) to
38 work on simple strings, too. Call the C{feed} method with arbitrary blocks
39 of data, and override the C{stringReceived} method to get called for each
40 embedded netstring. The default implementation collects the netstrings in
41 the list C{self.strings}.
42 """
43
45
46
47 self.makeConnection(NullTransport())
48 self.strings = []
49
50 - def feed(self, data):
51 """
52 Add arbitrariliy-sized C{data} to the incoming-data buffer. Any
53 complete netstrings will trigger a call to the stringReceived method.
54
55 Note that this method (and the Twisted class it is based on) cannot
56 detect a trailing partial netstring at EOF - the data will be silently
57 ignored.
58
59 @raise C{twisted.protocols.basic.NetstringParseError}: if invalid
60 """
61 self.dataReceived(data)
62
63 if self.brokenPeer:
64 raise basic.NetstringParseError
65
67 self.strings.append(string)
68