Exemple #1
0
def set_up_con(con, data):
    Stdin(con)
    Stdout(con)

    HttpClient(con)
    xmap(con, CLOSE, lambda con, err: lose(con))
    con.dump(data)
Exemple #2
0
def set_up_con(con, data):
    Stdin(con)
    Stdout(con)

    HttpClient(con)
    xmap(con, HTTP_RESPONSE, handle_http_response)
    xmap(con, CLOSE, lambda con, err: lose(con))

    con.dump(data)
Exemple #3
0
def on_connect(con):
    # This protocol is responsible by spawning
    # the event LOAD. It takes care of spawning a CLOSE
    # event when the connection is over.
    Stdout(con)

    # This protocol is responsible by installing a dump method
    # into the con instance. It takes care of sending everything
    # that goes through the dump method.
    Stdin(con)

    # This protocol is used to break the stream of data into chunks delimited
    # by '\r\n'. So, if the network sends 'data1\r\ndata2\r\ndata3\r\n' it will
    # spawns three times the event FOUND. It will carry 'data1', 'data2', 'data3'.
    Shrug(con)

    # This untwisted protocol is a tiny implementation of irc protocol.
    # It handles about 80% of the irc events. It is possible to be improved
    # and handle 100% of all irc events.
    Irc(con)

    # We want to print out on the screen all data that comes from the irc server.
    xmap(con, LOAD, lambda con, data: sys.stdout.write('%s\n' % data))

    # When the connection is over we need to destroy the Spin instance. The
    # lose function takes care of doing that for us.
    xmap(con, CLOSE, lambda con, err: lose(con))

    # When the event 'PRIVMSG' happens then we will have our handle
    # on_privmsg called. You could experiment other irc commands.
    xmap(con, 'PRIVMSG', on_privmsg)

    # When the irc server requires us to send back a PONG :server.
    xmap(con, 'PING', on_ping)

    # Our nick.
    con.dump('NICK %s\r\n' % NICK)

    con.dump('USER %s %s %s :%s\r\n' % (IRC_X, IRC_Y, IRC_Z, IRC_W))

    # Finally, it joins the channel.
    con.dump('JOIN %s\r\n' % CHANNEL)
Exemple #4
0
    def handle_accept(self, local, client):
        """
        This method is not supposed to be called by functions outside
        this class.
        """

        Stdin(client)
        Stdout(client)

        HttpServer(client)
        Get(client)
        Post(client)

        # It serves to determine whether the client made
        # a request whose resource exists.
        # In case it didnt the connection is dropped.
        client.ACTIVE = False

        for ind in self.setup:
            ind(client)

        xmap(client, CLOSE, lambda con, err: lose(con))
Exemple #5
0
def set_up_con(server, con):
    Stdout(con)
    xmap(con, CLOSE, lambda con, err: lose(con))
    xmap(con, LOAD, lambda con, data: sys.stdout.write('%s\n' % data))