Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / TwistedQuotes / quoters.py
1 from random import choice
2
3 from zope.interface import implements
4
5 from TwistedQuotes import quoteproto
6
7
8
9 class StaticQuoter:
10     """
11     Return a static quote.
12     """
13
14     implements(quoteproto.IQuoter)
15
16     def __init__(self, quote):
17         self.quote = quote
18
19
20     def getQuote(self):
21         return self.quote
22
23
24
25 class FortuneQuoter:
26     """
27     Load quotes from a fortune-format file.
28     """
29     implements(quoteproto.IQuoter)
30
31     def __init__(self, filenames):
32         self.filenames = filenames
33
34
35     def getQuote(self):
36         quoteFile = file(choice(self.filenames))
37         quotes = quoteFile.read().split('\n%\n')
38         quoteFile.close()
39         return choice(quotes)