aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/test_everything.py2
-rw-r--r--_pytest/test_presencechange.py2
-rw-r--r--_pytest/test_process_message.py2
-rw-r--r--_pytest/test_processreply.py2
-rw-r--r--_pytest/test_processsubteamcreated.py2
-rw-r--r--_pytest/test_processsubteamupdated.py2
-rw-r--r--_pytest/test_processteamjoin.py2
-rw-r--r--_pytest/test_thread.py6
-rw-r--r--wee_slack.py45
9 files changed, 20 insertions, 45 deletions
diff --git a/_pytest/test_everything.py b/_pytest/test_everything.py
index 5aa5138..ed045ae 100644
--- a/_pytest/test_everything.py
+++ b/_pytest/test_everything.py
@@ -10,7 +10,7 @@ def test_everything(realish_eventrouter, team):
for fname in sorted(datafiles):
data = json.loads(open(fname, 'r').read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert len(realish_eventrouter.queue) == 14
diff --git a/_pytest/test_presencechange.py b/_pytest/test_presencechange.py
index a6e9eb6..ffe28c9 100644
--- a/_pytest/test_presencechange.py
+++ b/_pytest/test_presencechange.py
@@ -12,7 +12,7 @@ def test_PresenceChange(realish_eventrouter, team, user_alice):
"user": user_alice.identifier,
"presence": "away",
})
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert user_alice.presence == "active"
diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py
index eff81d4..1a1ab37 100644
--- a/_pytest/test_process_message.py
+++ b/_pytest/test_process_message.py
@@ -21,7 +21,7 @@ def test_process_message(realish_eventrouter, team, user_alice):
m["user"] = user_alice.id
team.ws.add(m)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
realish_eventrouter.handle_next()
realish_eventrouter.handle_next()
diff --git a/_pytest/test_processreply.py b/_pytest/test_processreply.py
index 8b95e11..59ff560 100644
--- a/_pytest/test_processreply.py
+++ b/_pytest/test_processreply.py
@@ -8,7 +8,7 @@ def test_process_reply(realish_eventrouter, team, channel_general):
message_text = 'reply test'
channel_general.send_message(message_text)
team.ws.add({'reply_to': 1, '_team': team.team_hash, 'ts': str(message_ts)})
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert message_ts in channel_general.messages
diff --git a/_pytest/test_processsubteamcreated.py b/_pytest/test_processsubteamcreated.py
index 6c2bb35..299ac6f 100644
--- a/_pytest/test_processsubteamcreated.py
+++ b/_pytest/test_processsubteamcreated.py
@@ -9,7 +9,7 @@ def test_process_subteam_created(realish_eventrouter, team):
datafile = '_pytest/data/websocket/1483975206.59-subteam_created.json'
data = json.loads(open(datafile, 'r').read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert len(team.subteams) == 2
diff --git a/_pytest/test_processsubteamupdated.py b/_pytest/test_processsubteamupdated.py
index 94c6054..e3eb824 100644
--- a/_pytest/test_processsubteamupdated.py
+++ b/_pytest/test_processsubteamupdated.py
@@ -9,7 +9,7 @@ def test_process_subteam_self_updated(realish_eventrouter, team):
datafile = '_pytest/data/websocket/1483975206.59-subteam_updated.json'
data = json.loads(open(datafile, 'r').read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
subteam = team.subteams['TGX0ALBK3']
diff --git a/_pytest/test_processteamjoin.py b/_pytest/test_processteamjoin.py
index 8e83458..f965bbb 100644
--- a/_pytest/test_processteamjoin.py
+++ b/_pytest/test_processteamjoin.py
@@ -12,7 +12,7 @@ def test_process_team_join(realish_eventrouter, team):
datafile = '_pytest/data/websocket/1485975606.59-team_join.json'
data = json.loads(open(datafile, 'r').read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert len(team.users) == 4
diff --git a/_pytest/test_thread.py b/_pytest/test_thread.py
index 1eea31f..6567065 100644
--- a/_pytest/test_thread.py
+++ b/_pytest/test_thread.py
@@ -12,7 +12,7 @@ def test_message_has_thread_suffix(realish_eventrouter, team, channel_general):
datafile = '_pytest/data/websocket/1485975824.48-message.json'
data = json.loads(open(datafile).read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
@@ -21,7 +21,7 @@ def test_message_has_thread_suffix(realish_eventrouter, team, channel_general):
datafile = '_pytest/data/websocket/1485975836.23-message.json'
data = json.loads(open(datafile).read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
@@ -30,7 +30,7 @@ def test_message_has_thread_suffix(realish_eventrouter, team, channel_general):
datafile = '_pytest/data/websocket/1485975842.1-message.json'
data = json.loads(open(datafile).read())
team.ws.add(data)
- realish_eventrouter.receive_ws_callback(team.team_hash)
+ realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
diff --git a/wee_slack.py b/wee_slack.py
index 751eab6..01b3fad 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -479,7 +479,8 @@ class EventRouter(object):
team.connect()
dbg("reconnecting {}".format(team))
- def receive_ws_callback(self, team_hash):
+ @utf8_decode
+ def receive_ws_callback(self, team_hash, fd):
"""
This is called by the global method of the same name.
It is triggered when we have incoming data on a websocket,
@@ -513,7 +514,9 @@ class EventRouter(object):
if self.recording:
self.record_event(message_json, 'type', 'websocket')
self.receive(message_json)
+ return w.WEECHAT_RC_OK
+ @utf8_decode
def receive_httprequest_callback(self, data, command, return_code, out, err):
"""
complete
@@ -524,11 +527,7 @@ class EventRouter(object):
where the request originated and route properly.
"""
request_metadata = self.retrieve_context(data)
- try:
- dbg("RECEIVED CALLBACK with request of {} id of {} and code {} of length {}".format(request_metadata.request, request_metadata.response_id, return_code, len(out)))
- except:
- dbg(request_metadata)
- return
+ dbg("RECEIVED CALLBACK with request of {} id of {} and code {} of length {}".format(request_metadata.request, request_metadata.response_id, return_code, len(out)))
if return_code == 0:
if len(out) > 0:
if request_metadata.response_id not in self.reply_buffer:
@@ -571,6 +570,7 @@ class EventRouter(object):
dbg('rtm.start failed with return_code {}. stack:\n{}'
.format(return_code, ''.join(traceback.format_stack())), level=5)
self.receive(request_metadata)
+ return w.WEECHAT_RC_OK
def receive(self, dataobj):
"""
@@ -672,12 +672,7 @@ class EventRouter(object):
dbg("Callback not implemented for event: {}".format(function_name))
-def handle_next(*args):
- """
- complete
- This is just a place to call the event router globally.
- This is a dirty hack. There must be a better way.
- """
+def handle_next(data, remaining_calls):
try:
EVENTROUTER.handle_next()
except:
@@ -766,29 +761,6 @@ def local_process_async_slack_api_request(request, event_router):
@utf8_decode
-def receive_httprequest_callback(data, command, return_code, out, err):
- """
- complete
- This is a dirty hack. There must be a better way.
- """
- # def url_processor_cb(data, command, return_code, out, err):
- EVENTROUTER.receive_httprequest_callback(data, command, return_code, out, err)
- return w.WEECHAT_RC_OK
-
-
-@utf8_decode
-def receive_ws_callback(*args):
- """
- complete
- The first arg is all we want here. It contains the team
- hash which is set when we _hook the descriptor.
- This is a dirty hack. There must be a better way.
- """
- EVENTROUTER.receive_ws_callback(args[0])
- return w.WEECHAT_RC_OK
-
-
-@utf8_decode
def ws_ping_cb(data, remaining_calls):
for team in EVENTROUTER.teams.values():
if team.ws and team.connected:
@@ -5101,6 +5073,9 @@ if __name__ == "__main__":
EVENTROUTER = EventRouter()
# setup_trace()
+ receive_httprequest_callback = EVENTROUTER.receive_httprequest_callback
+ receive_ws_callback = EVENTROUTER.receive_ws_callback
+
# WEECHAT_HOME = w.info_get("weechat_dir", "")
# Global var section