~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        self._medium = medium
36
36
        self._base = base
37
37
 
 
38
    def _build_client_protocol(self):
 
39
        version = self._medium.protocol_version()
 
40
        request = self._medium.get_request()
 
41
        if version == 2:
 
42
            smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
43
        else:
 
44
            smart_protocol = protocol.SmartClientRequestProtocolOne(request)
 
45
        return smart_protocol
 
46
 
38
47
    def call(self, method, *args):
39
48
        """Call a method on the remote server."""
40
49
        result, protocol = self.call_expecting_body(method, *args)
49
58
            result, smart_protocol = smart_client.call_expecting_body(...)
50
59
            body = smart_protocol.read_body_bytes()
51
60
        """
52
 
        request = self._medium.get_request()
53
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
61
        smart_protocol = self._build_client_protocol()
54
62
        smart_protocol.call(method, *args)
55
63
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
56
64
 
63
71
                raise TypeError('args must be byte strings, not %r' % (args,))
64
72
        if type(body) is not str:
65
73
            raise TypeError('body must be byte string, not %r' % (body,))
66
 
        request = self._medium.get_request()
67
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
 
74
        smart_protocol = self._build_client_protocol()
68
75
        smart_protocol.call_with_body_bytes((method, ) + args, body)
69
76
        return smart_protocol.read_response_tuple()
70
77
 
77
84
                raise TypeError('args must be byte strings, not %r' % (args,))
78
85
        if type(body) is not str:
79
86
            raise TypeError('body must be byte string, not %r' % (body,))
80
 
        request = self._medium.get_request()
81
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
87
        smart_protocol = self._build_client_protocol()
82
88
        smart_protocol.call_with_body_bytes((method, ) + args, body)
83
89
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
84
90