Ejemplo n.º 1
0
from untwisted.utils.stdio import LOAD, CLOSE
from untwisted.network import Spin, xmap, get_event, spawn, zmap
from urllib import urlencode

HTTP_RESPONSE = get_event()

class HttpClient(object):

    def __init__(self, spin):

        """

        """

        xmap(spin, LOAD, self.get_header)
        xmap(spin, CLOSE,  self.spawn_response)

        self.spin     = spin
        self.header   = ''
        self.data     = ''
        self.response = ''
        self.size     = None

    def get_header(self, spin, data):
        """

        """

        DELIM       = '\r\n\r\n'
        self.header = self.header + data
Ejemplo n.º 2
0
from untwisted.network import xmap, spawn, get_event
from untwisted.utils.stdio import LOAD

BOX = get_event()

class Fixed(object):
    """
    A protocol for fixed chunks.

    It spawns BOX when the accumulator hits the specified
    size in bytes.
    """

    def __init__(self, spin, size=4):
        xmap(spin, LOAD, self.update)

        self.box  = ''
        self.size = size

    def update(self, spin, data):
        self.box = self.box + data

        while len(self.box) >= self.size:
            chunk    = buffer(self.box, 0, 4)
            self.box = buffer(self.box, 4)
            spawn(spin, BOX, chunk)

Ejemplo n.º 3
0
from untwisted.network import Spin, spawn, xmap, zmap, get_event, READ, WRITE
from untwisted.usual import debug
from collections import deque
import socket

from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN

CLOSE_ERR_CODE = (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF)
ACCEPT_ERR_CODE = (EWOULDBLOCK, ECONNABORTED, EAGAIN)
CLOSE = get_event()
ACCEPT = get_event()
CONNECT = get_event()
CONNECT_ERR = get_event()
LOAD = get_event()
DUMPED = get_event()
RECV_ERR = get_event()
SEND_ERR = get_event()
ACCEPT_ERR = get_event()
READ_ERR = get_event()
DUMPED_FILE = get_event()
CLOSE_ERR = get_event()


class Stdin:
    """ 
    This class implements a protocol that manages
    the sending of data. The method 'dump' is used to append 
    a chunk of text on top of a queue.
    
    Whenever we are ready to write 'update' method pops a chunk of data 
Ejemplo n.º 4
0
from untwisted.network import Spin, spawn, xmap, zmap, get_event, READ, WRITE
from untwisted.usual import debug
from collections import deque
import socket

from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN 

CLOSE_ERR_CODE   = (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF)
ACCEPT_ERR_CODE  = (EWOULDBLOCK, ECONNABORTED, EAGAIN)
CLOSE            = get_event()
ACCEPT           = get_event()
CONNECT          = get_event()
CONNECT_ERR      = get_event()
LOAD             = get_event()
DUMPED           = get_event()
RECV_ERR         = get_event()
SEND_ERR         = get_event()
ACCEPT_ERR       = get_event()
READ_ERR         = get_event()
DUMPED_FILE      = get_event()
CLOSE_ERR        = get_event()


class Stdin:
    """ 
    This class implements a protocol that manages
    the sending of data. The method 'dump' is used to append 
    a chunk of text on top of a queue.
    
    Whenever we are ready to write 'update' method pops a chunk of data 
Ejemplo n.º 5
0
from untwisted.network import xmap, spawn, get_event
from untwisted.utils.stdio import LOAD

BOX = get_event()


class Fixed(object):
    """
    A protocol for fixed chunks.

    It spawns BOX when the accumulator hits the specified
    size in bytes.
    """
    def __init__(self, spin, size=4):
        xmap(spin, LOAD, self.update)

        self.box = ''
        self.size = size

    def update(self, spin, data):
        self.box = self.box + data

        while len(self.box) >= self.size:
            chunk = buffer(self.box, 0, 4)
            self.box = buffer(self.box, 4)
            spawn(spin, BOX, chunk)