~stacyharper/wee-matter

1e4b17ebd5847faa0bbff7423d995d966e73f365 — Stacy Harper 15 days ago bae7582 develop
WIP: handle one queued query at a time
1 files changed, 8 insertions(+), 2 deletions(-)

M wee_matter/http.py
M wee_matter/http.py => wee_matter/http.py +8 -2
@@ 17,6 17,10 @@ from wee_matter.server import (connect_server_cb, connect_server_teams_cb,
                               connect_server_users_cb, connect_server_team_channel_cb,
                               connect_server_team_cb, new_user_cb)

enqueued_requests = []
queue_paused = False
response_buffers = {}

def build_file_url(file_id, server):
    return wee_matter.server.server_root_url(server) + "/api/v4/files/" + file_id



@@ 27,7 31,6 @@ def singularity_cb(data, command, rc, out, err):

    return weechat.WEECHAT_RC_OK

response_buffers = {}
def buffered_response_cb(data, command, rc, out, err):
    arg_search = re.search('([^\|]*)\|([^\|]*)\|(.*)', data)
    if not arg_search:


@@ 47,19 50,22 @@ def buffered_response_cb(data, command, rc, out, err):
    response = response_buffers[response_buffer_name] + out
    del response_buffers[response_buffer_name]

    queue_paused = False
    return eval(real_cb)(real_data, command, rc, response, err)

def build_buffer_cb_data(url, cb, cb_data):
    return "{}|{}|{}".format(url, cb, cb_data)

enqueued_requests = []
def enqueue_request(method, *params):
    enqueued_requests.append([method, params])

def handle_queued_request_cb(data, remaining_calls):
    if not enqueued_requests:
        return weechat.WEECHAT_RC_OK
    if queue_paused:
        return weechat.WEECHAT_RC_OK

    queue_paused = True
    request = enqueued_requests.pop(0)
    eval(request[0])(*request[1])
    return weechat.WEECHAT_RC_OK