示例#1
0
def metrics():
    """Return Prometheus metrics"""
    return generate_latest()
    response = Response()
    response.set_header('Content-Type',
                        'text/plain; version=0.0.4; charset=utf-8')
    response.body = generate_latest()
    return response
示例#2
0
def download_hard(cluster):
    g = get_network_from_cluster(cluster)
    hard = cluster_hard(g)
    s = str(hard)
    r = Response(body=s, status=200)
    r.set_header('Content-Type', 'text/txt')
    r.set_header('Content-Disposition', 'attachment; filename="phylonetwork_soft.txt"')
    return r
示例#3
0
def enable_cors(request: Request,
                response: Response,
                allow_credentials: bool = True,
                max_age: int = 86400) -> bool:
    """
This function detects whether the request is a cross-origin request or 
a preflight request based on certain characteristic headers, 
and then adds the corresponding response headers as needed.

    :param request: The bottle.request object (current request).
    :param response: The bottle.response object.
    :param allow_credentials: A bool flag indicates whether to send the response header "Access-Control-Allow-Credentials: true", if the request is a cross-origin request.
    :param max_age: The number of seconds that the results of the preflight request can be cached, if the request is a preflight request.
    :return: A Boolean value tells the caller whether the request is just a preflight request, so no further processing is required.
    """
    is_preflight = False

    origin = request.get_header('Origin')
    if not origin:
        return is_preflight

    host = request.get_header('Host')
    if not host:
        host = request.urlparts.netloc

    if origin.lower().endswith('//' + host.lower()):
        return is_preflight

    response.set_header('Access-Control-Allow-Origin', origin)

    if allow_credentials:
        response.set_header('Access-Control-Allow-Credentials', 'true')

    if request.method == 'OPTIONS':
        cors_method = request.get_header('Access-Control-Request-Method')
        if cors_method:
            response.set_header('Access-Control-Allow-Methods', cors_method)
            if max_age:
                response.set_header('Access-Control-Max-Age', str(max_age))
            is_preflight = True

        cors_headers = request.get_header('Access-Control-Request-Headers')
        if cors_headers:
            response.set_header('Access-Control-Allow-Headers', cors_headers)

    return is_preflight
示例#4
0
文件: web.py 项目: XuanShine/PyAccess
def turn(state, relai_ch):
    lock_door.turn(state, int(relai_ch))
    resp = Response(f"{datetime.now().strftime('%H:%M:%S')} {relai_ch} : {state}")
    resp.set_header('Access-Control-Allow-Origin', '*')
    return resp
示例#5
0
@route("/network/<cluster>/soft/download")
def download_soft(cluster):
    g = get_network_from_cluster(cluster)
    async = not DEBUG
    q = Queue(connection=Redis(), default_timeout=60*15, async=async)
    job = q.enqueue(cluster_soft, g)
    for i in range(10):
        if not job.result:
            time.sleep(5)
        else:
            break
    else:
        redirect("/?error='problem generating the file'")
    s = str(job.result)
    r = Response(body=s, status=200)
    r.set_header('Content-Type', 'text/txt')
    r.set_header('Content-Disposition', 'attachment; filename="phylonetwork_soft.txt"')
    return r

###
# Queues and jobs
@route("/job/families/<queue_key>/<job_id>")
def process_job_treechild(queue_key, job_id):
    redis_connection = Redis()
    q = Queue.from_queue_key(queue_key, redis_connection)
    job = q.safe_fetch_job(job_id)
    if job.result != None:
        # This construction may seem weird but the tree-child families may return
        # empty so we cannot just check against «if job.result»
        if not job.result:
            return {'status': 'done', 'value': "", }