/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/transport/remote.py

  • Committer: John Arbash Meinel
  • Date: 2007-06-28 23:18:09 UTC
  • mfrom: (2562 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070628231809-pqbt7puoqj8bl07b
[merge] bzr.dev 2562

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    # RemoteTransport is an adapter from the Transport object model to the 
75
75
    # SmartClient model, not an encoder.
76
76
 
77
 
    def __init__(self, url, clone_from=None, medium=None):
 
77
    def __init__(self, url, clone_from=None, medium=None, _client=None):
78
78
        """Constructor.
79
79
 
 
80
        :param clone_from: Another RemoteTransport instance that this one is
 
81
            being cloned from.  Attributes such as credentials and the medium
 
82
            will be reused.
80
83
        :param medium: The medium to use for this RemoteTransport. This must be
81
84
            supplied if clone_from is None.
 
85
        :param _client: Override the _SmartClient used by this transport.  This
 
86
            should only be used for testing purposes; normally this is
 
87
            determined from the medium.
82
88
        """
83
89
        ### Technically super() here is faulty because Transport's __init__
84
90
        ### fails to take 2 parameters, and if super were to choose a silly
97
103
            # reuse same connection
98
104
            self._medium = clone_from._medium
99
105
        assert self._medium is not None
 
106
        if _client is None:
 
107
            self._client = client._SmartClient(self._medium)
 
108
        else:
 
109
            self._client = _client
100
110
 
101
111
    def abspath(self, relpath):
102
112
        """Return the full url to the given relative path.
123
133
            return True
124
134
        elif resp == ('no', ):
125
135
            return False
 
136
        elif (resp == ('error', "Generic bzr smart protocol error: "
 
137
                                "bad request 'Transport.is_readonly'") or
 
138
              resp == ('error', "Generic bzr smart protocol error: "
 
139
                                "bad request u'Transport.is_readonly'")):
 
140
            # XXX: nasty hack: servers before 0.16 don't have a
 
141
            # 'Transport.is_readonly' verb, so we do what clients before 0.16
 
142
            # did: assume False.
 
143
            return False
126
144
        else:
127
145
            self._translate_error(resp)
128
 
        assert False, 'weird response %r' % (resp,)
 
146
        raise errors.UnexpectedSmartServerResponse(resp)
129
147
 
130
148
    def get_smart_client(self):
131
149
        return self._medium
160
178
 
161
179
    def _call2(self, method, *args):
162
180
        """Call a method on the remote server."""
163
 
        return client._SmartClient(self._medium).call(method, *args)
 
181
        return self._client.call(method, *args)
164
182
 
165
183
    def _call_with_body_bytes(self, method, args, body):
166
184
        """Call a method on the remote server with body bytes."""
167
 
        smart_client = client._SmartClient(self._medium)
168
 
        return smart_client.call_with_body_bytes(method, args, body)
 
185
        return self._client.call_with_body_bytes(method, args, body)
169
186
 
170
187
    def has(self, relpath):
171
188
        """Indicate whether a remote file of the given name exists or not.
488
505
        """After connecting HTTP Transport only deals in relative URLs."""
489
506
        # Adjust the relpath based on which URL this smart transport is
490
507
        # connected to.
491
 
        base = self._http_transport.base
 
508
        base = urlutils.normalize_url(self._http_transport.base)
492
509
        url = urlutils.join(self.base[len('bzr+'):], relpath)
493
510
        url = urlutils.normalize_url(url)
494
511
        return urlutils.relative_url(base, url)
523
540
        # We either use the exact same http_transport (for child locations), or
524
541
        # a clone of the underlying http_transport (for parent locations).  This
525
542
        # means we share the connection.
526
 
        normalized_rel_url = urlutils.relative_url(self.base, abs_url)
 
543
        norm_base = urlutils.normalize_url(self.base)
 
544
        norm_abs_url = urlutils.normalize_url(abs_url)
 
545
        normalized_rel_url = urlutils.relative_url(norm_base, norm_abs_url)
527
546
        if normalized_rel_url == ".." or normalized_rel_url.startswith("../"):
528
547
            http_transport = self._http_transport.clone(normalized_rel_url)
529
548
        else: