Sophie

Sophie

distrib > Mageia > 6 > x86_64 > by-pkgid > 09408f3c1571cbb746da49a1d2f22702 > files > 2852

python-twisted-17.5.0-1.mga6.x86_64.rpm

from random import choice

from zope.interface import implementer

from TwistedQuotes import quoteproto



@implementer(quoteproto.IQuoter)
class StaticQuoter:
    """
    Return a static quote.
    """
    def __init__(self, quote):
        self.quote = quote


    def getQuote(self):
        return self.quote



@implementer(quoteproto.IQuoter)
class FortuneQuoter:
    """
    Load quotes from a fortune-format file.
    """
    def __init__(self, filenames):
        self.filenames = filenames


    def getQuote(self):
        with open(choice(self.filenames)) as quoteFile:
            quotes = quoteFile.read().split('\n%\n')
        return choice(quotes)