Esempio n. 1
0
    def test_parse_notification(self):
        parser = APSParser()
        message, rest = parser.parseMessage(self.marshalledMessage)

        fields = self.messageFields
        self.assertEquals(message.recipientPushToken,
                          fields['recipientPushToken'])
        self.assertEquals(message.topic, fields['topic'])
        self.assertEquals(message.payload, fields['payload'])
        self.assertEquals(message.responseToken, fields['responseToken'])
        self.assertEquals(message.expires, 'N\xadd\xa4')
        self.assertEquals(message.timestamp, '\x12Q6\xbaf\t\xc8\x00')
        self.assertEquals(message.unknownString4, fields['unknownString4'])
Esempio n. 2
0
    def test_parse_notification(self):
        parser = APSParser()
        message, rest = parser.parseMessage(NOTIFICATION_MARSHALLED)

        self.assertEquals(message.recipientPushToken,
                          NOTIFICATION_DICT['recipientPushToken'])
        self.assertEquals(message.topic,
                          NOTIFICATION_DICT['topic'])
        self.assertEquals(message.payload,
                          NOTIFICATION_DICT['payload'])
        self.assertEquals(message.messageId,
                          NOTIFICATION_DICT['messageId'])
        self.assertEquals(message.expires,
                          NOTIFICATION_DICT['expires'])
        self.assertEquals(message.timestamp,
                          NOTIFICATION_DICT['timestamp'])
        self.assertEquals(message.storageFlags,
                          NOTIFICATION_DICT['storageFlags'])
Esempio n. 3
0
class MessageProxy(protocol.Protocol, BaseDispatch, object):
    peer = None
    peer_type = None  # device or server

    def __init__(self):
        self._parser = APSParser()
        self._source = None
        self._buffer = b''

    def setPeer(self, peer):
        self.peer = peer

    def dataReceived(self, data):
        buff = self._buffer + data

        while self._parser.isMessageComplete(buff):
            message, length = self._parser.parseMessage(buff)
            messageData = buff[:length]
            buff = buff[length:]
            self.handleMessage(message, messageData)

        self._buffer = buff

    def handleMessage(self, message, data):
        forward = self.dispatch(self.peer_type, message)
        if forward:
            self.sendToPeer(data)

    def sendToPeer(self, data):
        self.peer.transport.write(data)
        # FIXME implement in own handler
        # log.msg(repr(message))
        # FIXME implement in own handler
        # if hasattr(message, 'pushToken'):
        #     self.updatePushToken(caller, message.pushToken)

    def connectionLost(self, reason):
        # TODO notify handlers
        # FIXME fix this shutdown
        if self.peer is not None:
            self.peer.transport.loseConnection()
            self.peer = None
        else:
            log.msg("Unable to connect to peer: %s" % (reason, ))
Esempio n. 4
0
class MessageProxy(protocol.Protocol, BaseDispatch, object):
    peer = None
    peer_type = None  # device or server

    def __init__(self):
        self._parser = APSParser()
        self._source = None
        self._buffer = b''

    def setPeer(self, peer):
        self.peer = peer

    def dataReceived(self, data):
        buff = self._buffer + data

        while self._parser.isMessageComplete(buff):
            message, length = self._parser.parseMessage(buff)
            messageData = buff[:length]
            buff = buff[length:]
            self.handleMessage(message, messageData)

        self._buffer = buff

    def handleMessage(self, message, data):
        forward = self.dispatch(self.peer_type, message)
        if forward:
            self.sendToPeer(data)

    def sendToPeer(self, data):
        self.peer.transport.write(data)
        # FIXME implement in own handler
        # log.msg(repr(message))
        # FIXME implement in own handler
        # if hasattr(message, 'pushToken'):
        #     self.updatePushToken(caller, message.pushToken)

    def connectionLost(self, reason):
        # TODO notify handlers
        # FIXME fix this shutdown
        if self.peer is not None:
            self.peer.transport.loseConnection()
            self.peer = None
        else:
            log.msg("Unable to connect to peer: %s" % (reason,))
Esempio n. 5
0
    def test_parse_notification(self):
        parser = APSParser()
        message, rest = parser.parseMessage(self.marshalledMessage)

        fields = self.messageFields
        self.assertEquals(message.recipientPushToken,
                          fields['recipientPushToken'])
        self.assertEquals(message.topic,
                          fields['topic'])
        self.assertEquals(message.payload,
                          fields['payload'])
        self.assertEquals(message.responseToken,
                          fields['responseToken'])
        self.assertEquals(message.expires,
                          'N\xadd\xa4')
        self.assertEquals(message.timestamp,
                          '\x12Q6\xbaf\t\xc8\x00')
        self.assertEquals(message.unknownString4,
                          fields['unknownString4'])