~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-17 02:44:40 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071217024440-gb6e5qds0ol0r6sz
Dump help topics into text files in doc/en/user-reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import urllib
18
17
from urlparse import urlparse
19
18
 
20
19
from bzrlib.smart import protocol
21
 
from bzrlib import urlutils
 
20
from bzrlib.urlutils import unescape
22
21
 
23
22
 
24
23
class _SmartClient(object):
25
24
 
26
 
    def __init__(self, shared_connection):
27
 
        """Constructor.
28
 
 
29
 
        :param shared_connection: a bzrlib.transport._SharedConnection
30
 
        """
31
 
        self._shared_connection = shared_connection
 
25
    def __init__(self, shared_medium):
 
26
        self._shared_medium = shared_medium
32
27
 
33
28
    def get_smart_medium(self):
34
 
        return self._shared_connection.connection
 
29
        return self._shared_medium.connection
35
30
 
36
31
    def call(self, method, *args):
37
32
        """Call a method on the remote server."""
48
43
            body = smart_protocol.read_body_bytes()
49
44
        """
50
45
        request = self.get_smart_medium().get_request()
51
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
 
46
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
52
47
        smart_protocol.call(method, *args)
53
48
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
54
49
 
66
61
        smart_protocol.call_with_body_bytes((method, ) + args, body)
67
62
        return smart_protocol.read_response_tuple()
68
63
 
69
 
    def call_with_body_bytes_expecting_body(self, method, args, body):
70
 
        """Call a method on the remote server with body bytes."""
71
 
        if type(method) is not str:
72
 
            raise TypeError('method must be a byte string, not %r' % (method,))
73
 
        for arg in args:
74
 
            if type(arg) is not str:
75
 
                raise TypeError('args must be byte strings, not %r' % (args,))
76
 
        if type(body) is not str:
77
 
            raise TypeError('body must be byte string, not %r' % (body,))
78
 
        request = self.get_smart_medium().get_request()
79
 
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
80
 
        smart_protocol.call_with_body_bytes((method, ) + args, body)
81
 
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
82
 
 
83
64
    def remote_path_from_transport(self, transport):
84
65
        """Convert transport into a path suitable for using in a request.
85
66
        
87
68
        anything but path, so it is only safe to use it in requests sent over
88
69
        the medium from the matching transport.
89
70
        """
90
 
        if self._shared_connection.base.startswith('bzr+http://'):
91
 
            medium_base = self._shared_connection.base
92
 
        else:
93
 
            medium_base = urlutils.join(self._shared_connection.base, '/')
94
 
            
95
 
        rel_url = urlutils.relative_url(medium_base, transport.base)
96
 
        return urllib.unquote(rel_url)
 
71
        return unescape(urlparse(transport.base)[2]).encode('utf8')