[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Python or Perl for a Debian maintainance project?



DISCLAIMER for the humor impaired:
  This is not intended as a Python Coding Style Demonstration. Merely a
  bit of fun.


# andrew.py --- simple module to handle mailing list messages

import sets, random


class AIError(Exception):
    """Exception raised when there is a blatant bug in the AI."""

class AbortMessage(Exception):
    """Exception raised when I'd better shut up for the rest of the message."""


def try_to_impress_with_stats_stuff(point):
    print \
      general_statement_about_statistics_to_show_I_know_a_lot_on_the_subject()
    if random.randint(0,3) >= 2:
        insult_or_similar()


def all_others_are_assholes_and_I_know_better(point):
    print "All others are clueless morons. I use their crappy work every " \
          "day but don't count on me to tell them about the One True Way!"


def insult_or_similar(point):
    if point.numbers_were_involved():
        print "Learn to count."
    else:
        if random.randint(0, 1):
            print "You're on drugs."
        else:
            print "%s %s" % (random_stuff(), "You're talking shit.")


def blurb(point):
    # XXX Probably incomplete. Needs more research.
    print "Hah."


def pretend_he_cannot_express_his_thoughts_if_any(point):
    print "Well yeah, that's what we're talking about. What are you trying " \
          "to say, again?"


def pretend_the_point_was_irrelevant(point):
    print "You've got no idea what I was talking about and have managed " \
          "to be completely irrelevant."
    try_to_introduce_a_new_vaguely_similar_subject_as_THE_subject()
    raise AbortMessage()


def language_diversion(point):
    pretend_the_point_was_written_with_an_ambiguous_English_construct()
    do_ignore(point)


def handle(point, techniques):
    """Handle a point in a mailing-list message.

    point      -- the point I am replying to
    techniques -- available techniques for this message

    'techniques' should be a dictionary where keys indicate the type of the
    point I am replying to with associated values being sets of available
    techniques for this type of point that were not yet used in the message
    the point belongs to.

    Beware: 'techniques' is modified by this function: the chosen technique,
            if any, will be taken out of the relevant set.
    
    """
    if point.is_benchmark():
        try:
            techniques["benchmark"].pop()(point)
        except KeyError:
            snip(point)
    elif point.is_assertion():
        if point.i_think_i_am_right():
            print "You're very wrong."
            argue(point)
        else:
            try:
                techniques["correct_assertion"].pop()(point)
            except KeyError:
                print "Bwah? Wrong context."
                make_up_purported_context()
                raise AbortMessage()
    else:
        raise AIError("I was not programmed to handle the following "
                      "point:\n\n%s" % point)


def handle_message(message):
    """Handle a message from a mailing-list.

    message -- the message I am to reply to

    """ 
    techniques = {
        "benchmark": sets.Set([try_to_impress_with_stats_stuff]),
        "correct_assertion": sets.Set(
          [all_others_are_assholes_and_I_know_better,
           insult_or_similar,
           blurb,
           pretend_he_cannot_express_his_thoughts_if_any,
           pretend_the_point_was_irrelevant,
           language_diversion])
        }
    
    try:
        for point in message:
            try:
                handle(point, techniques)
            except AbortMessage:
                break

        send_reply()

-- 
Florent



Reply to: