Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / TwistedQuotes / quoteproto.py
1 from zope.interface import Interface
2
3 from twisted.internet.protocol import Factory, Protocol
4
5
6
7 class IQuoter(Interface):
8     """
9     An object that returns quotes.
10     """
11     def getQuote():
12         """
13         Return a quote.
14         """
15
16
17
18 class QOTD(Protocol):
19     def connectionMade(self):
20         self.transport.write(self.factory.quoter.getQuote()+'\r\n')
21         self.transport.loseConnection()
22
23
24
25 class QOTDFactory(Factory):
26     """
27     A factory for the Quote of the Day protocol.
28
29     @type quoter: L{IQuoter} provider
30     @ivar quoter: An object which provides L{IQuoter} which will be used by
31         the L{QOTD} protocol to get quotes to emit.
32     """
33     protocol = QOTD
34
35     def __init__(self, quoter):
36         self.quoter = quoter