Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrDoctorWho <mrdoctorwho@gmail.com>2015-03-22 15:38:41 +0300
committermrDoctorWho <mrdoctorwho@gmail.com>2015-03-22 15:38:41 +0300
commit16e2f2be16ff35e4f564badf9fd30922a5330726 (patch)
treeab4e5504dc5554c8e16967c5952ae059cc498664
parente7b8c4cdf979da60e1471a0c7c839ce0de77291e (diff)
Fixed ValueError if wrong JSON was coming in decoder
Fixed possible KeyError in Poll if user disappeared while we were initializing Poll
-rw-r--r--gateway.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/gateway.py b/gateway.py
index 741c906..c4b3f02 100644
--- a/gateway.py
+++ b/gateway.py
@@ -828,7 +828,10 @@ class User(object):
logger.error("longpoll: no data. Will request again")
return 1
- data = json.loads(data)
+ try:
+ data = json.loads(data)
+ except ValueError:
+ return 1
if "failed" in data:
logger.debug("longpoll: failed. Searching for new server (jid: %s)" % self.source)
@@ -921,7 +924,6 @@ class Poll:
Adds user in self.__list if no errors
"""
try:
- # Getting socket for polling it by select()
opener = user.vk.makePoll()
except Exception as e:
if not isinstance(e, api.LongPollError):
@@ -972,13 +974,16 @@ class Poll:
if user in cls.__buff:
cls.__buff.remove(user)
return None
+
if Transport[user.source].vk.initPoll():
with cls.__lock:
logger.debug("longpoll: successfully initialized longpoll (jid: %s)" % user.source)
if user not in cls.__buff:
return None
cls.__buff.remove(user)
- cls.__add(Transport[user.source])
+ # Check if user still in transport when we finally came down here
+ if user.source in Transport:
+ cls.__add(Transport[user.source])
break
time.sleep(10)
else: