~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

Merge trunk

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
17
18
from urlparse import urlparse
18
19
 
19
20
from bzrlib.smart import protocol
65
66
        smart_protocol.call_with_body_bytes((method, ) + args, body)
66
67
        return smart_protocol.read_response_tuple()
67
68
 
 
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
 
68
83
    def remote_path_from_transport(self, transport):
69
84
        """Convert transport into a path suitable for using in a request.
70
85
        
72
87
        anything but path, so it is only safe to use it in requests sent over
73
88
        the medium from the matching transport.
74
89
        """
75
 
        if self._shared_connection.base.startswith('bzr+http://'):
 
90
        base = self._shared_connection.base
 
91
        if base.startswith('bzr+http://') or base.startswith('bzr+https://'):
76
92
            medium_base = self._shared_connection.base
77
93
        else:
78
94
            medium_base = urlutils.join(self._shared_connection.base, '/')
79
95
            
80
 
        return urlutils.relative_url(medium_base, transport.base).encode('utf8')
 
96
        rel_url = urlutils.relative_url(medium_base, transport.base)
 
97
        return urllib.unquote(rel_url)