aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTollef Fog Heen <tfheen@err.no>2018-03-09 20:52:58 +0100
committerTollef Fog Heen <tfheen@err.no>2018-03-11 07:56:59 +0100
commitc2b67f978579e353ff02c59bcc879f47d8c7f0b4 (patch)
treea65b084e3771bd3ec6a1e0017d718f4f8f6e4793 /wee_slack.py
parent42604089ca82f87598857df1418ccc5cc52088aa (diff)
downloadwee-slack-c2b67f978579e353ff02c59bcc879f47d8c7f0b4.tar.gz
Use StringIO instead of string concatenation
This makes a big difference for larger teams where rtm.start can time out just due to Python's strings being immutable. Fixes: #516
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/wee_slack.py b/wee_slack.py
index b6d0449..7e29f8b 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -20,6 +20,10 @@ import collections
import ssl
import random
import string
+try:
+ from cStringIO import StringIO
+except:
+ from StringIO import StringIO
from websocket import create_connection, WebSocketConnectionClosedException
@@ -364,15 +368,11 @@ class EventRouter(object):
return
if return_code == 0:
if len(out) > 0:
- if request_metadata.response_id in self.reply_buffer:
- # dbg("found response id in reply_buffer", True)
- self.reply_buffer[request_metadata.response_id] += out
- else:
- # dbg("didn't find response id in reply_buffer", True)
- self.reply_buffer[request_metadata.response_id] = ""
- self.reply_buffer[request_metadata.response_id] += out
+ if request_metadata.response_id not in self.reply_buffer:
+ self.reply_buffer[request_metadata.response_id] = StringIO()
+ self.reply_buffer[request_metadata.response_id].write(out)
try:
- j = json.loads(self.reply_buffer[request_metadata.response_id])
+ j = json.loads(self.reply_buffer[request_metadata.response_id].getvalue())
except:
pass
# dbg("Incomplete json, awaiting more", True)
@@ -397,8 +397,8 @@ class EventRouter(object):
self.delete_context(data)
else:
if request_metadata.response_id not in self.reply_buffer:
- self.reply_buffer[request_metadata.response_id] = ""
- self.reply_buffer[request_metadata.response_id] += out
+ self.reply_buffer[request_metadata.response_id] = StringIO()
+ self.reply_buffer[request_metadata.response_id].write(out)
def receive_json(self, data):
"""