~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

Merge from 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):
25
28
 
26
 
    def __init__(self, shared_connection):
 
29
    def __init__(self, medium, base):
27
30
        """Constructor.
28
31
 
29
 
        :param shared_connection: a bzrlib.transport._SharedConnection
 
32
        :param medium: a SmartClientMedium
 
33
        :param base: a URL
30
34
        """
31
 
        self._shared_connection = shared_connection
32
 
 
33
 
    def get_smart_medium(self):
34
 
        return self._shared_connection.connection
 
35
        self._medium = medium
 
36
        self._base = base
35
37
 
36
38
    def _build_client_protocol(self):
37
 
        medium = self.get_smart_medium()
38
 
        version = medium.protocol_version()
39
 
        request = medium.get_request()
 
39
        version = self._medium.protocol_version()
 
40
        request = self._medium.get_request()
40
41
        if version == 2:
41
42
            smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
42
43
        else:
94
95
        anything but path, so it is only safe to use it in requests sent over
95
96
        the medium from the matching transport.
96
97
        """
97
 
        base = self._shared_connection.base
98
 
        if base.startswith('bzr+http://') or base.startswith('bzr+https://'):
99
 
            medium_base = self._shared_connection.base
 
98
        base = self._base
 
99
        if (base.startswith('bzr+http://') or base.startswith('bzr+https://')
 
100
            or base.startswith('http://') or base.startswith('https://')):
 
101
            medium_base = self._base
100
102
        else:
101
 
            medium_base = urlutils.join(self._shared_connection.base, '/')
 
103
            medium_base = urlutils.join(self._base, '/')
102
104
            
103
105
        rel_url = urlutils.relative_url(medium_base, transport.base)
104
106
        return urllib.unquote(rel_url)
 
107