Ejemplo n.º 1
0
    def test_63_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65536, fin=1)
        self.assertEqual(len(f.build()), 65546)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65536, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 65550)
Ejemplo n.º 2
0
    def test_63_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 65536, fin=1)
        self.assertEqual(len(f.build()), 65546)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT,
                  body=b'*' * 65536,
                  masking_key=mask,
                  fin=1)
        self.assertEqual(len(f.build()), 65550)
Ejemplo n.º 3
0
    def test_7_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b'', fin=1)
        self.assertEqual(len(f.build()), 2)

        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 125, fin=1)
        self.assertEqual(len(f.build()), 127)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b'', masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 6)

        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 125, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 131)
Ejemplo n.º 4
0
    def test_16_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 126, fin=1)
        self.assertEqual(len(f.build()), 130)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65535, fin=1)
        self.assertEqual(len(f.build()), 65539)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 126, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 134)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 65535, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 65543)
Ejemplo n.º 5
0
    def test_7_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b"", fin=1)
        self.assertEqual(len(f.build()), 2)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 125, fin=1)
        self.assertEqual(len(f.build()), 127)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b"", masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 6)

        f = Frame(opcode=OPCODE_TEXT, body=b"*" * 125, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 131)
Ejemplo n.º 6
0
    def test_16_bit_length(self):
        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 126, fin=1)
        self.assertEqual(len(f.build()), 130)

        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 65535, fin=1)
        self.assertEqual(len(f.build()), 65539)

        mask = os.urandom(4)
        f = Frame(opcode=OPCODE_TEXT, body=b'*' * 126, masking_key=mask, fin=1)
        self.assertEqual(len(f.build()), 134)

        f = Frame(opcode=OPCODE_TEXT,
                  body=b'*' * 65535,
                  masking_key=mask,
                  fin=1)
        self.assertEqual(len(f.build()), 65543)
Ejemplo n.º 7
0
    def test_masking(self):
        mask = "7\xfa!="
        f = Frame(opcode=OPCODE_TEXT,
                  body='Hello', masking_key=mask, fin=1)

        spec_says = '\x81\x857\xfa!=\x7f\x9fMQX'
        self.assertEqual(f.build(), spec_says)
Ejemplo n.º 8
0
    def test_masking(self):
        if py3k: mask = b"7\xfa!="
        else: mask = "7\xfa!="
        f = Frame(opcode=OPCODE_TEXT, body=b'Hello', masking_key=mask, fin=1)

        if py3k: spec_says = b'\x81\x857\xfa!=\x7f\x9fMQX'
        else: spec_says = '\x81\x857\xfa!=\x7f\x9fMQX'
        self.assertEqual(f.build(), spec_says)
Ejemplo n.º 9
0
    def test_opcodes(self):
        for opcode in [OPCODE_CONTINUATION, OPCODE_TEXT, OPCODE_BINARY, OPCODE_CLOSE, OPCODE_PING, OPCODE_PONG]:
            f = Frame(opcode=opcode, body=b"", fin=1)
            byte = ord(f.build()[0])
            self.assertTrue(byte & opcode == opcode)

        f = Frame(opcode=0x3, body=b"", fin=1)
        self.assertRaises(ValueError, f.build)
Ejemplo n.º 10
0
    def test_masking(self):
        if py3k: mask = b"7\xfa!="
        else: mask = "7\xfa!="
        f = Frame(opcode=OPCODE_TEXT,
                  body=enc('Hello'),
                  masking_key=mask, fin=1)

        if py3k: spec_says = b'\x81\x857\xfa!=\x7f\x9fMQX'
        else: spec_says = '\x81\x857\xfa!=\x7f\x9fMQX'
        self.assertEqual(f.build(), spec_says)
Ejemplo n.º 11
0
    def test_opcodes(self):
        for opcode in [
                OPCODE_CONTINUATION, OPCODE_TEXT, OPCODE_BINARY, OPCODE_CLOSE,
                OPCODE_PING, OPCODE_PONG
        ]:
            f = Frame(opcode=opcode, body=b'', fin=1)
            byte = ord(f.build()[0])
            self.assertTrue(byte & opcode == opcode)

        f = Frame(opcode=0x3, body=b'', fin=1)
        self.assertRaises(ValueError, f.build)
Ejemplo n.º 12
0
 def received_message(self, m):
     # Assuming type of arraybuffer
     xx = N.fromstring(m.data, N.int16, count=5)
     # xx = N.fromstring(m.data, N.float32, count=4)
     print xx
     xx = xx*2;
     f = Frame(OPCODE_BINARY, xx.tostring(), fin=1)
     b = f.build()
     yy = BinaryMessage(b)
     for conn in SUBSCRIBERS:
     	conn.send(yy)
Ejemplo n.º 13
0
 def test_protocol_exception_from_frame_parsing(self):
     payload = struct.pack("!H", 1000) + b'hello'
     f = Frame(opcode=OPCODE_CLOSE, body=payload,
               fin=1, masking_key=os.urandom(4))
     f.rsv1 = 1
     f = f.build()
     s = Stream()
     self.assertEqual(len(s.errors), 0)
     self.assertEqual(s.closing, None)
     s.parser.send(f)
     self.assertEqual(s.closing, None)
     self.assertEqual(type(s.errors[0]), CloseControlMessage)
     self.assertEqual(s.errors[0].code, 1002)
Ejemplo n.º 14
0
 def test_passing_encoded_string(self):
     # once encoded the u'\xe9' character will be of length 2
     f = Frame(opcode=OPCODE_TEXT,
               body=u'\xe9trange'.encode('utf-8'),
               fin=1)
     self.assertEqual(len(f.build()), 10)
Ejemplo n.º 15
0
 def test_passing_encoded_string(self):
     # once encoded the u'\xe9' character will be of length 2
     f = Frame(opcode=OPCODE_TEXT, body=u'\xe9trange'.encode('utf-8'), fin=1)
     self.assertEqual(len(f.build()), 10)