/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Andrew Bennetts
  • Date: 2010-03-18 23:11:15 UTC
  • mto: This revision was merged to the branch mainline in revision 5117.
  • Revision ID: andrew.bennetts@canonical.com-20100318231115-zrjij60gnj7qg6jw
Consolidate changes, try to minimise unnecessary changes and tidy up those that kept.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        )
50
50
 
51
51
 
52
 
def _recv_all(socket, bytes):
53
 
    """Receive an exact number of bytes.
54
 
 
55
 
    Regular Socket.recv() may return less than the requested number of bytes,
56
 
    depending on what's in the OS buffer.  MSG_WAITALL is not available
57
 
    on all platforms, but this should work everywhere.  This will return
58
 
    less than the requested amount if the remote end closes.
59
 
 
60
 
    This isn't optimized and is intended mostly for use in testing. Should be
61
 
    replaced with a more appropriate interface.
62
 
    """
63
 
    b = ''
64
 
    reporter = lambda n, rw: None
65
 
    while len(b) < bytes:
66
 
        new = medium._read_bytes_from_socket(socket, reporter, bytes - len(b))
67
 
        if new == '':
68
 
            break # eof
69
 
        b += new
70
 
    return b
71
 
 
72
 
 
73
52
class StringIOSSHVendor(object):
74
53
    """A SSH vendor that uses StringIO to buffer writes and answer reads."""
75
54
 
148
127
        """
149
128
        def _receive_bytes_on_server():
150
129
            connection, address = sock.accept()
151
 
            bytes.append(_recv_all(connection, 3))
 
130
            bytes.append(osutils.recv_all(connection, 3))
152
131
            connection.close()
153
132
        t = threading.Thread(target=_receive_bytes_on_server)
154
133
        t.start()
755
734
        client_sock.sendall(rest_of_request_bytes)
756
735
        server._serve_one_request(server_protocol)
757
736
        server_sock.close()
758
 
        self.assertEqual(expected_response, _recv_all(client_sock, 50),
 
737
        self.assertEqual(expected_response, osutils.recv_all(client_sock, 50),
759
738
                         "Not a version 2 response to 'hello' request.")
760
739
        self.assertEqual('', client_sock.recv(1))
761
740