~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from urlparse import urlparse
19
19
 
20
20
from bzrlib.smart import protocol
21
 
from bzrlib import urlutils
 
21
from bzrlib import (
 
22
    errors,
 
23
    urlutils,
 
24
    )
22
25
 
23
26
 
24
27
class _SmartClient(object):
32
35
        self._medium = medium
33
36
        self._base = base
34
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
 
35
47
    def call(self, method, *args):
36
48
        """Call a method on the remote server."""
37
49
        result, protocol = self.call_expecting_body(method, *args)
46
58
            result, smart_protocol = smart_client.call_expecting_body(...)
47
59
            body = smart_protocol.read_body_bytes()
48
60
        """
49
 
        request = self._medium.get_request()
50
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
61
        smart_protocol = self._build_client_protocol()
51
62
        smart_protocol.call(method, *args)
52
63
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
53
64
 
60
71
                raise TypeError('args must be byte strings, not %r' % (args,))
61
72
        if type(body) is not str:
62
73
            raise TypeError('body must be byte string, not %r' % (body,))
63
 
        request = self._medium.get_request()
64
 
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
 
74
        smart_protocol = self._build_client_protocol()
65
75
        smart_protocol.call_with_body_bytes((method, ) + args, body)
66
76
        return smart_protocol.read_response_tuple()
67
77
 
74
84
                raise TypeError('args must be byte strings, not %r' % (args,))
75
85
        if type(body) is not str:
76
86
            raise TypeError('body must be byte string, not %r' % (body,))
77
 
        request = self._medium.get_request()
78
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
87
        smart_protocol = self._build_client_protocol()
79
88
        smart_protocol.call_with_body_bytes((method, ) + args, body)
80
89
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
81
90
 
95
104
            
96
105
        rel_url = urlutils.relative_url(medium_base, transport.base)
97
106
        return urllib.unquote(rel_url)
 
107