Permalink
Browse files

Fixed py3 compat

  • Loading branch information...
1 parent 822f45b commit cdbd6e45e37bb3ad9576fb7ea1d872d3fc55e6eb @tgalal committed Apr 24, 2016
View
@@ -5,7 +5,7 @@
import platform
import sys
-deps = ['python-dateutil', 'argparse', 'python-axolotl>=0.1.7']
+deps = ['python-dateutil', 'argparse', 'python-axolotl>=0.1.35', 'six']
if sys.version_info < (2,7):
deps += ['importlib']
@@ -132,7 +132,8 @@ def handlePreKeyWhisperMessage(self, node):
sessionCipher = self.getSessionCipher(pkMessageProtocolEntity.getAuthor(False))
plaintext = sessionCipher.decryptPkmsg(preKeyWhisperMessage)
if enc.getVersion() == 2:
- padding = ord(plaintext[-1]) & 0xFF
+ paddingByte = plaintext[-1] if type(plaintext[-1]) is int else ord(plaintext[-1])
+ padding = paddingByte & 0xFF
self.parseAndHandleMessageProto(pkMessageProtocolEntity, plaintext[:-padding])
else:
self.handleConversationMessage(node, plaintext)
@@ -146,7 +147,8 @@ def handleWhisperMessage(self, node):
plaintext = sessionCipher.decryptMsg(whisperMessage)
if enc.getVersion() == 2:
- padding = ord(plaintext[-1]) & 0xFF
+ paddingByte = plaintext[-1] if type(plaintext[-1]) is int else ord(plaintext[-1])
+ padding = paddingByte & 0xFF
self.parseAndHandleMessageProto(encMessageProtocolEntity, plaintext[:-padding])
else:
self.handleConversationMessage(encMessageProtocolEntity.toProtocolTreeNode(), plaintext)
@@ -160,7 +162,9 @@ def handleSenderKeyMessage(self, node):
try:
plaintext = groupCipher.decrypt(enc.getData())
padding = ord(plaintext[-1]) & 0xFF
- self.parseAndHandleMessageProto(encMessageProtocolEntity, plaintext[:-padding])
+ plaintext = plaintext[:-padding]
+ plaintext = plaintext.encode() if sys.version_info >= (3, 0) else plaintext
+ self.parseAndHandleMessageProto(encMessageProtocolEntity, plaintext)
except NoSessionException as e:
logger.error(e)
@@ -211,7 +211,7 @@ def sendToGroup(self, node, retryReceiptEntity = None):
def sendToGroup(resultNode, requestEntity):
groupInfo = InfoGroupsResultIqProtocolEntity.fromProtocolTreeNode(resultNode)
- jids = groupInfo.getParticipants().keys()
+ jids = list(groupInfo.getParticipants().keys()) #keys in py3 returns dict_keys
jids.remove(ownJid)
return self.ensureSessionsAndSendToGroup(node, jids)
@@ -19,9 +19,9 @@ def __init__(self, _id, jid, remoteRegistrationId, receiptTimestamp, retryTimest
def setRetryData(self, remoteRegistrationId, v, count, retryTimestamp):
self.remoteRegistrationId = remoteRegistrationId
- self.v = v
- self.count = count
- self.retryTimestamp = retryTimestamp
+ self.v = int(v)
+ self.count = int(count)
+ self.retryTimestamp = int(retryTimestamp)
def toProtocolTreeNode(self):
node = super(RetryIncomingReceiptProtocolEntity, self).toProtocolTreeNode()

0 comments on commit cdbd6e4

Please sign in to comment.