Exemplo n.º 1
0
def call_function(module, function_name, parameters):
    try:
        f = getattr(module, function_name)
    except AttributeError:
        raise Exception("No matching function availble. "
                        "You asked for %s with these parameters %s!" %
                        (function_name, parameters))
    results = f(**parameters)
    response = Response(content=results)
    if hasattr(f, 'cacheable') and f.cacheable:
        response.cacheable = True
    if hasattr(f, 'stream') and f.stream and STREAMING:
        response.type = "stream"
    elif response.content.__class__.__name__ == 'generator':
        response.type = "chunks"
    return response
Exemplo n.º 2
0
def call_function(module, function_name, parameters):
    try:
        f = getattr(module, function_name)
    except AttributeError:
        raise Exception("No matching function availble. "
                        "You asked for %s with these parameters %s!" % (
                            function_name, parameters))
    results = f(**parameters)
    response = Response(content=results)
    if hasattr(f, 'cacheable') and f.cacheable:
        response.cacheable = True
    if hasattr(f, 'stream') and f.stream and STREAMING:
        response.type = "stream"
    elif response.content.__class__.__name__ == 'generator':
        response.type = "chunks"
    return response
Exemplo n.º 3
0
def serve_file(file_path):
    response = Response()
    size = os.path.getsize(file_path)
    mimetype = mimetypes.guess_type(file_path)
    response.set_header("Content-type", mimetype[0] or 'text/plain')
    response.set_header("Content-length", str(size))
    response.set_header("Cache-Control", 'public, max-age=22222222')
    response.content = open(file_path, 'rb')
    response.type = "file"
    return response
Exemplo n.º 4
0
def serve_file(file_path):
    response = Response()
    size = os.path.getsize(file_path)
    mimetype = mimetypes.guess_type(file_path)
    response.set_header("Content-type", mimetype[0] or 'text/plain')
    response.set_header("Content-length", str(size))
    response.set_header("Cache-Control", 'public, max-age=22222222')
    response.content = open(file_path, 'rb')
    response.type = "file"
    return response
Exemplo n.º 5
0
def serve_file(file_path):
    response = Response()
    fs = os.stat(file_path)
    mimetype = mimetypes.guess_type(file_path)
    response.set_header("Content-length", str(fs.st_size))
    if file_path.endswith('.manifest'):
        response.set_header("Content-type", 'text/cache-manifest')
        response.set_header("Expires", 'access')
    else:
        response.set_header("Content-type", mimetype[0] or 'text/plain')
        response.set_header("Last-Modified", date_time_string(fs.st_mtime))
    response.content = open(file_path, 'rb')
    response.type = "file"
    return response
Exemplo n.º 6
0
def serve_file(file_path):
    response = Response()
    fs = os.stat(file_path)
    mimetype = mimetypes.guess_type(file_path)
    response.set_header("Content-length", str(fs.st_size))
    if file_path.endswith('.manifest'):
        response.set_header("Content-type", 'text/cache-manifest')
        response.set_header("Expires", 'access')
    else:
        response.set_header("Content-type", mimetype[0] or 'text/plain')
        response.set_header("Last-Modified", date_time_string(fs.st_mtime))
    response.content = open(file_path, 'rb')
    response.type = "file"
    return response
Exemplo n.º 7
0
def not_found_error(path):
    response = Response()
    response.status = '404 NOT FOUND'
    response.content = '404 File not found'
    response.type = 'plaintext'
    return response
Exemplo n.º 8
0
def not_found_error(path):
    response = Response()
    response.status = '404 NOT FOUND'
    response.content = '404 File not found'
    response.type = 'plaintext'
    return response