~jk0/nova/xs-ipv6

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/TwistedQuotes/quoteproto.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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