/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/smart/client.py

  • Committer: Andrew Bennetts
  • Date: 2008-04-07 10:34:57 UTC
  • mfrom: (3344 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3349.
  • Revision ID: andrew.bennetts@canonical.com-20080407103457-ro4t95pd3imwt0zw
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
class _SmartClient(object):
28
28
 
29
 
    def __init__(self, shared_connection):
 
29
    def __init__(self, medium, base):
30
30
        """Constructor.
31
31
 
32
 
        :param shared_connection: a bzrlib.transport._SharedConnection
 
32
        :param medium: a SmartClientMedium
 
33
        :param base: a URL
33
34
        """
34
 
        self._shared_connection = shared_connection
35
 
 
36
 
    def get_smart_medium(self):
37
 
        return self._shared_connection.connection
 
35
        self._medium = medium
 
36
        self._base = base
38
37
 
39
38
    def call(self, method, *args):
40
39
        """Call a method on the remote server."""
50
49
            result, smart_protocol = smart_client.call_expecting_body(...)
51
50
            body = smart_protocol.read_body_bytes()
52
51
        """
53
 
        request = self.get_smart_medium().get_request()
 
52
        request = self._medium.get_request()
54
53
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
55
54
        smart_protocol.call(method, *args)
56
55
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
64
63
                raise TypeError('args must be byte strings, not %r' % (args,))
65
64
        if type(body) is not str:
66
65
            raise TypeError('body must be byte string, not %r' % (body,))
67
 
        request = self.get_smart_medium().get_request()
 
66
        request = self._medium.get_request()
68
67
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
69
68
        smart_protocol.call_with_body_bytes((method, ) + args, body)
70
69
        return smart_protocol.read_response_tuple()
78
77
                raise TypeError('args must be byte strings, not %r' % (args,))
79
78
        if type(body) is not str:
80
79
            raise TypeError('body must be byte string, not %r' % (body,))
81
 
        request = self.get_smart_medium().get_request()
 
80
        request = self._medium.get_request()
82
81
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
83
82
        smart_protocol.call_with_body_bytes((method, ) + args, body)
84
83
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
90
89
        anything but path, so it is only safe to use it in requests sent over
91
90
        the medium from the matching transport.
92
91
        """
93
 
        base = self._shared_connection.base
94
 
        if base.startswith('bzr+http://') or base.startswith('bzr+https://'):
95
 
            medium_base = self._shared_connection.base
 
92
        base = self._base
 
93
        if (base.startswith('bzr+http://') or base.startswith('bzr+https://')
 
94
            or base.startswith('http://') or base.startswith('https://')):
 
95
            medium_base = self._base
96
96
        else:
97
 
            medium_base = urlutils.join(self._shared_connection.base, '/')
 
97
            medium_base = urlutils.join(self._base, '/')
98
98
            
99
99
        rel_url = urlutils.relative_url(medium_base, transport.base)
100
100
        return urllib.unquote(rel_url)