Пример #1
0
 def test_non_blocking_timeout(self):
     client = RendezvousClient(nat_type="preserving",
                               rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     assert (s.recv_line() == u"")
     assert (s.recv(1) == u"")
     s.close()
Пример #2
0
    def test_recv_recvline_switch(self):
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()
        s.send_line("SOURCE TCP 32")
        ret = s.recv(1)
        assert(ret[0] == u"R")
        assert(not len(s.buf))
        s.buf = u"test"
        ret = s.recv(1)
        assert(ret[0] == u"E")
        assert(s.buf == u"test")
        s.buf = u"example\r\nxsfsdf"
        junk = s.buf[:]
        s.send_line("SOURCE TCP 50")

        ret = s.recv_line()
        print(ret)
        assert("example" in ret)
        print(s.buf)
        print(junk)
        ret = s.recv_line()
        assert("xsfsdf" in ret)
        print(s.buf)
        print(junk)
        ret = s.recv_line()
        assert("MOTE" in ret)

        s.close()
Пример #3
0
 def test_non_blocking_timeout(self):
     client = RendezvousClient(nat_type="preserving",
                               rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     assert(s.recv_line() == u"")
     assert(s.recv(1) == u"")
     s.close()
Пример #4
0
    def test_recv_recvline_switch(self):
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()
        s.send_line("SOURCE TCP 32")
        ret = s.recv(1)
        assert (ret[0] == u"R")
        assert (not len(s.buf))
        s.buf = u"test"
        ret = s.recv(1)
        assert (ret[0] == u"E")
        assert (s.buf == u"test")
        s.buf = u"example\r\nxsfsdf"
        junk = s.buf[:]
        s.send_line("SOURCE TCP 50")

        ret = s.recv_line()
        print(ret)
        assert ("example" in ret)
        print(s.buf)
        print(junk)
        ret = s.recv_line()
        assert ("xsfsdf" in ret)
        print(s.buf)
        print(junk)
        ret = s.recv_line()
        assert ("MOTE" in ret)

        s.close()
Пример #5
0
 def test_blocking_timeout(self):
     client = RendezvousClient(nat_type="preserving", rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     t = time.time()
     s.recv_line(timeout=1)
     if time.time() - t >= 4:
         print("Manual timeout failed.")
         assert 0
     s.close()
Пример #6
0
 def test_blocking_timeout(self):
     client = RendezvousClient(nat_type="preserving",
                               rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     t = time.time()
     s.recv_line(timeout=1)
     if time.time() - t >= 4:
         print("Manual timeout failed.")
         assert 0
     s.close()
Пример #7
0
 def test_encoding(self):
     client = RendezvousClient(nat_type="preserving",
                               rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     s.send_line("SOURCE TCP 50")
     ret = s.recv(1, encoding="ascii")
     if sys.version_info >= (3, 0, 0):
         assert(type(ret) == bytes)
     else:
         assert(type(ret) == str)
     assert(ret == b"R")
     ret = s.recv_line()
     assert(u"EMOTE" in ret)
     s.close()
Пример #8
0
 def test_encoding(self):
     client = RendezvousClient(nat_type="preserving",
                               rendezvous_servers=rendezvous_servers)
     s = client.server_connect()
     s.send_line("SOURCE TCP 50")
     ret = s.recv(1, encoding="ascii")
     if sys.version_info >= (3, 0, 0):
         assert (type(ret) == bytes)
     else:
         assert (type(ret) == str)
     assert (ret == b"R")
     ret = s.recv_line()
     assert (u"EMOTE" in ret)
     s.close()
Пример #9
0
    def test_00001(self):
        from pyp2p.net import rendezvous_servers
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()

        # Test boostrap.
        s.send_line("BOOTSTRAP 1")
        nodes = s.recv_line()
        assert("NODES" in nodes)

        # Test source TCP.
        s.send_line("SOURCE TCP")
        src = s.recv_line()
        assert("REMOTE TCP" in src)

        # Doesn't test passive / sim listen
        # fight, accept, candidate, etc...
        # but that is tested in the net tests

        s.close()
Пример #10
0
    def test_00001(self):
        from pyp2p.net import rendezvous_servers
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()

        # Test boostrap.
        s.send_line("BOOTSTRAP 1")
        nodes = s.recv_line()
        assert ("NODES" in nodes)

        # Test source TCP.
        s.send_line("SOURCE TCP")
        src = s.recv_line()
        assert ("REMOTE TCP" in src)

        # Doesn't test passive / sim listen
        # fight, accept, candidate, etc...
        # but that is tested in the net tests

        s.close()
Пример #11
0
    def test_0000001_sock(self):
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()
        assert s.connected
        s.send_line("SOURCE TCP 323")
        assert s.connected
        line = s.recv_line()
        assert ("REMOTE" in line)

        s = Sock("www.example.com", 80, blocking=0, timeout=10)
        data = "GET / HTTP/1.1\r\n"
        data += "Connection: close\r\n"
        data += "Host: www.example.com\r\n\r\n"
        s.send(data, send_all=1)
        replies = ""
        while s.connected:
            for reply in s:
                # Output should be unicode.
                if sys.version_info >= (3, 0, 0):
                    assert (type(reply) == str)
                else:
                    assert (type(reply) == unicode)

                replies += reply
                print(reply)

        assert (s.connected != 1)
        assert (replies != "")

        s.close()
        s.reconnect()
        s.close()

        s = Sock("www.example.com", 80, blocking=1, timeout=10)
        s.send_line("GET / HTTP/1.1")
        s.send_line("Host: www.example.com\r\n")
        line = s.recv_line()
        print(line)
        print(type(line))
        print(s.buf)
        print(type(s.buf))
        assert (line, "HTTP/1.1 200 OK")
        if sys.version_info >= (3, 0, 0):
            assert (type(line) == str)
        else:
            assert (type(line) == unicode)
        s.close()

        s = Sock()
        s.buf = "\r\nx\r\n"
        x = s.parse_buf()
        assert (x[0] == "x")

        s.buf = "\r\n"
        x = s.parse_buf()
        assert (x == [])

        s.buf = "\r\n\r\n"
        x = s.parse_buf()
        assert (x == [])

        s.buf = "\r\r\n\r\n"
        x = s.parse_buf()
        assert (x[0] == "\r")

        s.buf = "\r\n\r\n\r\nx"
        x = s.parse_buf()
        assert (x == [])

        s.buf = "\r\n\r\nx\r\nsdfsdfsdf\r\n"
        x = s.parse_buf()
        assert (x[0] == "x" and x[1] == "sdfsdfsdf")

        s.buf = "sdfsdfsdf\r\n"
        s.parse_buf()
        s.buf += "abc\r\n"
        x = s.parse_buf()
        assert (x[0] == "abc")

        s.buf += "\r\ns\r\n"
        x = s.parse_buf()
        assert (x[0] == "s")

        s.buf = "reply 1\r\nreply 2\r\n"
        s.replies = []
        s.update()
        assert (s.pop_reply(), "reply 1")
        assert (s.replies[0], "reply 2")
Пример #12
0
    def test_0000001_sock(self):
        client = RendezvousClient(nat_type="preserving",
                                  rendezvous_servers=rendezvous_servers)
        s = client.server_connect()
        assert s.connected
        s.send_line("SOURCE TCP 323")
        assert s.connected
        line = s.recv_line()
        assert ("REMOTE" in line)

        s = Sock("www.example.com", 80, blocking=0, timeout=10)
        data = "GET / HTTP/1.1\r\n"
        data += "Connection: close\r\n"
        data += "Host: www.example.com\r\n\r\n"
        s.send(data, send_all=1)
        replies = ""
        while s.connected:
            for reply in s:
                # Output should be unicode.
                if sys.version_info >= (3, 0, 0):
                    assert (type(reply) == str)
                else:
                    assert (type(reply) == unicode)

                replies += reply
                print(reply)

        assert (s.connected != 1)
        assert (replies != "")

        s.close()
        s.reconnect()
        s.close()

        s = Sock("www.example.com", 80, blocking=1, timeout=10)
        s.send_line("GET / HTTP/1.1")
        s.send_line("Host: www.example.com\r\n")
        line = s.recv_line()
        print(line)
        print(type(line))
        print(s.buf)
        print(type(s.buf))
        assert (line, "HTTP/1.1 200 OK")
        if sys.version_info >= (3, 0, 0):
            assert (type(line) == str)
        else:
            assert (type(line) == unicode)
        s.close()

        s = Sock()
        s.buf = b"\r\nx\r\n"
        x = s.parse_buf()
        assert (x[0] == "x")

        s.buf = b"\r\n"
        x = s.parse_buf()
        assert (x == [])

        s.buf = b"\r\n\r\n"
        x = s.parse_buf()
        assert (x == [])

        s.buf = b"\r\r\n\r\n"
        x = s.parse_buf()
        assert (x[0] == "\r")

        s.buf = b"\r\n\r\n\r\nx"
        x = s.parse_buf()
        assert (x == [])

        s.buf = b"\r\n\r\nx\r\nsdfsdfsdf\r\n"
        x = s.parse_buf()
        assert (x[0] == "x" and x[1] == "sdfsdfsdf")

        s.buf = b"sdfsdfsdf\r\n"
        s.parse_buf()
        s.buf += b"abc\r\n"
        x = s.parse_buf()
        assert (x[0] == "abc")

        s.buf += b"\r\ns\r\n"
        x = s.parse_buf()
        assert (x[0] == "s")

        s.buf = b"reply 1\r\nreply 2\r\n"
        s.replies = []
        s.update()
        assert (s.pop_reply(), "reply 1")
        assert (s.replies[0], "reply 2")