Exemple #1
0
def post_words():
    body = bottle.request.json

    # check they've sent { "words" : "some sentence" }
    if not 'words' in body:
        bottle.response.status = '500 No words'
        return bottle.response

    # split it up into words
    msg_count = 0
    for word in body['words'].split(' '):
        with LOCK:
            # send it as a message
            message = {
                'word': word,
                'frontend': 'Python: {0}'.format(client.get_id())
            }
            print('Sending message: {0}'.format(message))
            send_queue.append({
                'topic': PUBLISH_TOPIC,
                'message': json.dumps(message)
            })
            msg_count += 1
            # send back a count of messages sent
            response = bottle.Response(
                body=json.dumps({'msgCount': msg_count}))
    return response
def get_uppercase_words():
    # do we have a message held?
    if len(recv_queue) == 0:
        # just return no-data
        bottle.response.status = 204
        return bottle.response
    else:
        # send the data to the caller
        data = recv_queue.pop(0)
        response = bottle.Response(body=json.dumps(data))
        response.content_type = 'application/json'
        return response
def post_words():
    body = bottle.request.json

    # check they've sent { "words" : "some sentence" }
    if not 'words' in body:
        bottle.response.status = '500 No words'
        return bottle.response

    # split it up into words
    msg_count = 0
    for word in body['words'].split(' '):
        with LOCK:
            # send it as a message
            message = {
                'word': word,
                'frontend': 'Python: {0}'.format(CLIENT_ID)
            }
            print('Sending response: {0}'.format(message))
            app.call(upcase_service, message, process_message)
            msg_count += 1
            # send back a count of messages sent
        response = bottle.Response(body=json.dumps({'msgCount': msg_count}))
    return response
    def hello(account_id):
        user_agent = bottle.request.headers['User-Agent']  # NOQA
        limit = bottle.request.query.limit or '10'  # NOQA

        return bottle.Response(body, headers=headers)
def new_response():
    return bottle.Response()
Exemple #6
0
def abort(code=500, text="Unknown Error."):
    """ Aborts execution and causes a HTTP error. """
    origin = bottle.request.headers.get("Origin")
    d = __cors_dict(origin)
    return bottle.Response(text, code, headers=d)
Exemple #7
0
def home(
    zoom: float = 1.7,
    xm: float = -2,
    xM: float = 1,
    ym: float = -1.5,
    yM: float = 1.5,
    s: int = DEFAULT_IMAGE_SIZE,
    new_x: int = None,
    new_y: int = None,
    newxy: str = None,
    maxiter: int = 100,
):
    if newxy:
        x, y = newxy[1:].split(",")
        return bottle.redirect(
            app.get_url(
                "home",
                zoom=zoom,
                xm=xm,
                xM=xM,
                ym=ym,
                yM=yM,
                s=s,
                new_x=x,
                new_y=y,
            ))
    if new_x is not None and new_y is not None:
        x_cells = np.linspace(xm, xM, s)
        y_cells = np.linspace(ym, yM, s)
        dx = x_cells[new_x] - x_cells[s // 2]
        dy = y_cells[new_y] - y_cells[s // 2]
        xm += dx
        xM += dx
        ym += dy
        yM += dy
        # ---------- re-scale
        cx, cy = ((xM - xm) / 2) + xm, ((yM - ym) / 2) + ym
        dx, dy = (xM - cx) / zoom, (yM - cy) / zoom
        xm, xM = cx - dx, cx + dx
        ym, yM = cy - dy, cy + dy
        return bottle.redirect(
            app.get_url(
                "home",
                zoom=zoom,
                xm=xm,
                xM=xM,
                ym=ym,
                yM=yM,
                s=s,
            ))
    image_link = f"http://localhost:8080/image/{xm}/{xM}/{ym}/{yM}/{s}/{maxiter}"
    href_link = (app.get_url(
        "home",
        zoom=zoom,
        xm=xm,
        xM=xM,
        ym=ym,
        yM=yM,
        s=s,
    ) + "&newxy=")
    with open("index.html", "r") as fl:
        html = fl.read().format(image_link=image_link,
                                href_link=href_link,
                                xm=xm,
                                xM=xM,
                                ym=ym,
                                yM=yM)
    resp = bottle.Response(body=html, status=200)
    resp.set_header("Content-type", "text/html")
    return resp
Exemple #8
0
def image(xmin, xmax, ymin, ymax, step=DEFAULT_IMAGE_SIZE, maxiter=100):
    img = get_image(float(xmin), float(xmax), float(ymin), float(ymax),
                    int(step), int(maxiter))
    resp = bottle.Response(body=img, status=200)
    resp.set_header("Content-Type", "image/png")
    return resp