diesel / diesel /

The default branch has multiple heads

Full commit
# vim:ts=4:sw=4:expandtab
'''An outgoing pipeline that can handle
strings or files.
    import cStringIO
except ImportError:
    raise ImportError, "cStringIO is required"

_obj_SIO = cStringIO.StringIO
_type_SIO = cStringIO.OutputType
def make_SIO(d):
    t = _obj_SIO()
    return t

def get_file_length(f):
    m = f.tell(), 2)
    r = f.tell()
    return r

class PipelineCloseRequest(Exception): pass
class PipelineClosed(Exception): pass
class Pipeline(object):
    '''A pipeline that supports appending strings or
    files and can read() transparently across object
    boundaries in the outgoing buffer.
    def __init__(self):
        self.line = []
        self.want_close = False

    def add(self, d):
        '''Add object `d` to the pipeline.
        if self.want_close:
            raise PipelineClosed

        if type(d) is str:
            if self.line and type(self.line[-1][0]) is _type_SIO:
                fd, l = self.line[-1]
                m = fd.tell()
      , 2)
                self.line[-1] = [fd, l + len(d)]
                self.line.append([make_SIO(d), len(d)])
            self.line.append([d, get_file_length(d)])

    def close_request(self):
        '''Add a close request to the outgoing pipeline.

        No more data will be allowed in the pipeline, and, when
        it is emptied, PipelineCloseRequest will be raised.
        self.want_close = True

    def read(self, amt):
        '''Read up to `amt` bytes off the pipeline.

        May raise PipelineCloseRequest if the pipeline is
        empty and the connected stream should be closed.
        if self.line == [] and self.want_close:
            raise PipelineCloseRequest

        rbuf = []
        read = 0
        while self.line and read < amt:
            data = self.line[0][0].read(amt - read)
            if data == '':
                del self.line[0]
                read += len(data)

        while self.line and self.line[0][1] == self.line[0][0].tell():
            del self.line[0]

        return ''.join(rbuf)
    def backup(self, d):
        '''Pop object d back onto the front the pipeline.

        Used in cases where not all data is sent() on the socket,
        for example--the remainder will be placed back in the pipeline.
        self.line.insert(0, [make_SIO(d), len(d)])

    def empty(self):
        '''Is the pipeline empty?

        A close request is "data" that needs to be consumed,
        return self.want_close == False and self.line == []