예제 #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')])
예제 #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')])
예제 #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~')
예제 #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~')
예제 #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 = []
예제 #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 = []
예제 #7
0
 def send(self, message):
     self.write_message(proto.encode(message))
     self.connection.delay_heartbeat()
예제 #8
0
 def send(self, message):
     self.write_message(proto.encode(message))
     self.connection.delay_heartbeat()