Ejemplo n.º 1
0
def outputfilter_post(filter):

    if filter.req.status != 500 and \
                filter.req.headers_out.has_key('tramline_remove_archive'):
        removeArchive(filter.req.headers_out['tramline_remove_archive'])

    if filter.req.status != 500 and filter.req.headers_out.has_key(
            'tramline_remove'):
        # log(filter.req.headers_out['tramline_remove'])
        removeFiles(filter.req.headers_out['tramline_remove'])

    if filter.req.status != 500 and filter.req.headers_out.has_key(
            'tramline_move'):
        # log(filter.req.headers_out['tramline_move'])
        moveFiles(filter.req.headers_out['tramline_move'])

    if filter.req.status != 500 and filter.req.headers_out.has_key(
            'tramline_archive'):
        # log(filter.req.headers_out['tramline_move'])
        archiveFile(filter.req.headers_out['tramline_archive'])

    # get id
    id = filter.req.headers_in.get('tramline_id')

    if id is None:
        # we're done now, just pass along data
        filter.pass_on()
        try:
            filter.flush()
        except:
            pass
        return

    # reuse existing processor instance based on id
    processor = theProcessorRegistry.getProcessor(int(id))

    is_ok = filter.req.headers_out.has_key('tramline_ok')
    if is_ok:
        # if the appserver said okay,
        processor.commit(filter.req)
    else:
        # if the appserver didn't say okay
        processor.abort()

    # remove the processor id from the request now, as we're done with it
    theProcessorRegistry.removeProcessor(processor)

    # remove the id from the request as well
    del filter.req.headers_in['tramline_id']

    # now pass along the data.
    filter.pass_on()
    try:
        filter.flush()
    except:
        pass
Ejemplo n.º 2
0
def outputfilter_get(filter):
    # remove something?


    if filter.req.status != 500 and \
                filter.req.headers_out.has_key('tramline_remove_archive'):
        removeArchive(filter.req.headers_out['tramline_remove_archive'])

    # check whether we want to do file serving using tramline
    if not filter.req.headers_out.has_key('tramline_file'):
        filter.pass_on()
        #filter.flush()
        return
    # now read file id
    data = []
    s = filter.read()
    while s:
        data.append(s)
        s = filter.read()
    file_id = ''.join(data)

    # when show a image
    if not file_id:
        filter.pass_on()
        try:
            filter.flush()
        except:
            pass
        return

    # XXX what if file doesn't exist? 404?
    p = getDownloadPath(filter.req, file_id)
    size = os.stat(p).st_size
    filter.req.headers_out['content-length'] = str(size)
    # filter.req.sendfile(p)
    f = open(p, 'rb')
    while True:
        data = f.read(FILE_CHUNKSIZE)
        if not data:
            break
        filter.write(data)
        # flush the data out as soon as possible, so we don't
        # waste memory
        filter.flush()
    f.close()
    # close filter if last read is None
    if s is None:
        filter.close()