Ejemplo n.º 1
0
    def update(self, spin):
        try:
            # If self.data is '' we read from the file.
            if not self.data:
                self.data = self.fd.read(self.BLOCK)
                # If self.data is '' then we are done.
                if not self.data:
                    # Spreads DUMPED_FILE so clients of this protocol
                    # can know when their files were sent.
                    zmap(spin, WRITE, self.update)
                    spawn(spin, DUMPED_FILE)

                    # We no more need to write.
                    # We are done.
                    return

            size = spin.send(self.data)

            # We use buffer to send faster.
            self.data = buffer(self.data, size)

        # If it arose error when sending we deal with it.
        except socket.error as excpt:
            err = excpt.args[0]
            if err in CLOSE_ERR_CODE:
                spawn(spin, CLOSE)
            else:
                spawn(spin, SEND_ERR, excpt)
        except IOError as excpt:
            err = excpt.args[0]
            spawn(spin, READ_ERR, err)
Ejemplo n.º 2
0
    def update(self, spin):
        try:
        # If self.data is '' we read from the file.
            if not self.data:
                self.data = self.fd.read(self.BLOCK)
        # If self.data is '' then we are done.
                if not self.data:
        # Spreads DUMPED_FILE so clients of this protocol 
        # can know when their files were sent.
                    zmap(spin, WRITE, self.update)
                    spawn(spin, DUMPED_FILE)

        # We no more need to write.
        # We are done.
                    return

            size = spin.send(self.data)

    # We use buffer to send faster.
            self.data = buffer(self.data, size)

        # If it arose error when sending we deal with it.
        except socket.error as excpt:
            err = excpt.args[0]
            if err in CLOSE_ERR_CODE:
                spawn(spin, CLOSE)
            else:
                spawn(spin, SEND_ERR, excpt)
        except IOError as excpt:
            err = excpt.args[0]
            spawn(spin, READ_ERR, err)
Ejemplo n.º 3
0
    def check_data_size(self):
        """

        """
        if not len(self.data) >= self.size:
            return

        zmap(self.spin, LOAD, self.get_data)
        self.spawn_response()
Ejemplo n.º 4
0
    def check_data_size(self):
        """

        """
        if not len(self.data) >= self.size:
            return

        zmap(self.spin, LOAD, self.get_data)
        self.spawn_response()
Ejemplo n.º 5
0
 def update(self, spin):
     # All linked to CONNECT is called.
     err = spin.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
     
     # If the err is non zero the socket is in error.
     if err != 0:
         spawn(spin, CONNECT_ERR, err)
     else:
         spawn(spin, CONNECT)
     # As we can connect just once, it unlinks self.update from 
     # WRITE.
         zmap(spin, WRITE, self.update)
Ejemplo n.º 6
0
    def update(self, spin):
        # All linked to CONNECT is called.
        err = spin.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)

        # If the err is non zero the socket is in error.
        if err != 0:
            spawn(spin, CONNECT_ERR, err)
        else:
            spawn(spin, CONNECT)
            # As we can connect just once, it unlinks self.update from
            # WRITE.
            zmap(spin, WRITE, self.update)
Ejemplo n.º 7
0
    def get_header(self, spin, data):
        """

        """

        DELIM       = '\r\n\r\n'
        self.header = self.header + data

        if not DELIM in data:
            return

        self.header, self.data     = self.header.split(DELIM, 1)
        self.response, self.header = self.split_header(self.header)
        zmap(spin, LOAD, self.get_header)
        xmap(spin, LOAD, self.get_data)
Ejemplo n.º 8
0
 def update(self, device):
     try:
         data = self.queue.popleft()
     # As device.write returns None
     # we don't need to worry whether it has sent all the bytes
     # unlike with sockets.
         device.write(data)
     except IndexError:
     # When the queue is empty then we don't need
     # the WRITE event.
         zmap(device, WRITE, self.update)
         spawn(device, DUMPED)
     except IOError as excpt:
     # If something went wrong it spawns CLOSE with err.
     # The err parameter gives a clue of what happened.
         err = excpt.args[0]
         spawn(device, CLOSE, err)
Ejemplo n.º 9
0
    def update(self, device):
        try:
            data = self.queue.popleft()
            device.write(data)  
        except IOError as excpt:
            err = excpt.args[0]
            spawn(device, CLOSE, err)
            debug()

        except IndexError: 
        # If the queue is empty we no more need
        # the WRITE event.
            zmap(device, WRITE, self.update)
        # It is important to know when all data was
        # fully sent. It spawns DUMPED when the queue
        # is empty.
            spawn(device, DUMPED)
Ejemplo n.º 10
0
    def update(self, spin):
        """
            This method is called on WRITE to send data.
            It attempts to optmize the job of sending bytes by using
            buffer. 
            
            The algorithm is explained in the class doc.

            Events: DUMPED, CLOSE, SEND_ERR

            See help(Stdin).
        """

        try:
            if not self.data:
                self.data = self.queue.popleft()

        # As we are in non blocking mode a call to send
        # doesn't block. We just need to know the amount
        # of bytes sent.
            size = spin.send(self.data)  

        # We move the pointer size bytes ahead.
            self.data = buffer(self.data, size)
        except socket.error as excpt:
            err = excpt.args[0]

        # The err value contains the socket status error code.
        # It is passed with either CLOSE or SEND_ERR so
        # users of this protocol can know what happened
        # exactly with the call to send.
            if err in CLOSE_ERR_CODE:
                spawn(spin, CLOSE, err)
            else:
                spawn(spin, SEND_ERR, err)
                debug()

        except IndexError: 
        # If the queue is empty we no more need
        # the WRITE event.
            zmap(spin, WRITE, self.update)

        # It is important to know when all data was
        # fully sent. It spawns DUMPED when the queue
        # is empty.
            spawn(spin, DUMPED)
Ejemplo n.º 11
0
    def update(self, device):
        try:
            data = self.queue.popleft()
            device.write(data)
        except IOError as excpt:
            err = excpt.args[0]
            spawn(device, CLOSE, err)
            debug()

        except IndexError:
            # If the queue is empty we no more need
            # the WRITE event.
            zmap(device, WRITE, self.update)
            # It is important to know when all data was
            # fully sent. It spawns DUMPED when the queue
            # is empty.
            spawn(device, DUMPED)
Ejemplo n.º 12
0
    def update(self, spin):
        """
            This method is called on WRITE to send data.
            It attempts to optmize the job of sending bytes by using
            buffer. 
            
            The algorithm is explained in the class doc.

            Events: DUMPED, CLOSE, SEND_ERR

            See help(Stdin).
        """

        try:
            if not self.data:
                self.data = self.queue.popleft()

        # As we are in non blocking mode a call to send
        # doesn't block. We just need to know the amount
        # of bytes sent.
            size = spin.send(self.data)

            # We move the pointer size bytes ahead.
            self.data = buffer(self.data, size)
        except socket.error as excpt:
            err = excpt.args[0]

            # The err value contains the socket status error code.
            # It is passed with either CLOSE or SEND_ERR so
            # users of this protocol can know what happened
            # exactly with the call to send.
            if err in CLOSE_ERR_CODE:
                spawn(spin, CLOSE, err)
            else:
                spawn(spin, SEND_ERR, err)
                debug()

        except IndexError:
            # If the queue is empty we no more need
            # the WRITE event.
            zmap(spin, WRITE, self.update)

            # It is important to know when all data was
            # fully sent. It spawns DUMPED when the queue
            # is empty.
            spawn(spin, DUMPED)
Ejemplo n.º 13
0
 def update(self, device):
     try:
         data = self.queue.popleft()
         # As device.write returns None
         # we don't need to worry whether it has sent all the bytes
         # unlike with sockets.
         device.write(data)
     except IndexError:
         # When the queue is empty then we don't need
         # the WRITE event.
         zmap(device, WRITE, self.update)
         spawn(device, DUMPED)
     except IOError as excpt:
         # If something went wrong it spawns CLOSE with err.
         # The err parameter gives a clue of what happened.
         err = excpt.args[0]
         spawn(device, CLOSE, err)
Ejemplo n.º 14
0
 def unset(con, *args):
     for key, value in events:
         zmap(irc.con, key, value)
Ejemplo n.º 15
0
def rm(server, nick, user, host, target, 
               msg, lang_x, lang_y, ident):
    zmap(server, ident, listen, lang_x, lang_y)
Ejemplo n.º 16
0
def rm(server, nick, user, host, target, msg, lang_x, lang_y, ident):
    zmap(server, ident, listen, lang_x, lang_y)