Esempio n. 1
0
def test_decode():
    # Test string decode
    eq_(proto.decode(proto.encode('abc')), [('~m~', 'abc')])

    # Test unicode decode
    eq_(proto.decode(proto.encode(u'\u0430\u0431\u0432')),
        [('~m~', u'\u0430\u0431\u0432'.encode('utf-8'))])

    # Test JSON decode
    eq_(proto.decode(proto.encode({'a': 'b'})), [('~m~', {'a': 'b'})])

    # Test seprate messages decoding
    eq_(proto.decode(proto.encode(['a', 'b'])), [('~m~', 'a'), ('~m~', 'b')])
Esempio n. 2
0
def test_decode():
    # Test string decode
    eq_(proto.decode(proto.encode('abc')), [('~m~', 'abc')])

    # Test unicode decode
    eq_(proto.decode(proto.encode(u'\u0430\u0431\u0432')),
        [('~m~', u'\u0430\u0431\u0432'.encode('utf-8'))])

    # Test JSON decode
    eq_(proto.decode(proto.encode({'a':'b'})),
        [('~m~', {'a':'b'})])

    # Test seprate messages decoding
    eq_(proto.decode(proto.encode(['a','b'])),
        [('~m~', 'a'), ('~m~', 'b')])
Esempio n. 3
0
def test_encode():
    # Test string encode
    eq_(proto.encode('abc'), '~m~3~m~abc')

    # Test dict encode
    eq_(proto.encode({'a':'b'}), '~m~13~m~~j~{"a": "b"}')

    # Test list encode
    eq_(proto.encode(['a','b']), '~m~1~m~a~m~1~m~b')

    # Test unicode
    eq_(proto.encode(u'\u0430\u0431\u0432'),
        '~m~6~m~' + u'\u0430\u0431\u0432'.encode('utf-8'))

    # Test special characters encoding
    eq_(proto.encode('~m~'), '~m~3~m~~m~')
Esempio n. 4
0
def test_encode():
    # Test string encode
    eq_(proto.encode('abc'), '~m~3~m~abc')

    # Test dict encode
    eq_(proto.encode({'a': 'b'}), '~m~13~m~~j~{"a": "b"}')

    # Test list encode
    eq_(proto.encode(['a', 'b']), '~m~1~m~a~m~1~m~b')

    # Test unicode
    eq_(proto.encode(u'\u0430\u0431\u0432'),
        '~m~6~m~' + u'\u0430\u0431\u0432'.encode('utf-8'))

    # Test special characters encoding
    eq_(proto.encode('~m~'), '~m~3~m~~m~')
Esempio n. 5
0
    def flush(self):
        """Send all pending messages to the associated request handler (if any)
        """
        if self.handler is None:
            return

        if not self.send_queue:
            return

        self.handler.data_available(proto.encode(self.send_queue))
        self.send_queue = []
Esempio n. 6
0
    def flush(self):
        """Send all pending messages to the associated request handler (if any)
        """
        if self.handler is None:
            return

        if not self.send_queue:
            return

        self.handler.data_available(proto.encode(self.send_queue))
        self.send_queue = []
Esempio n. 7
0
 def send(self, message):
     self.write_message(proto.encode(message))
     self.connection.delay_heartbeat()
Esempio n. 8
0
 def send(self, message):
     self.write_message(proto.encode(message))
     self.connection.delay_heartbeat()