/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: Martin Pool
  • Date: 2008-11-17 03:21:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3844.
  • Revision ID: mbp@sourcefrog.net-20081117032153-5al4ibc256whf5ut
Remove dead exports

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""RemoteTransport client for the smart-server.
18
18
 
34
34
    urlutils,
35
35
    )
36
36
from bzrlib.smart import client, medium
37
 
from bzrlib.symbol_versioning import (
38
 
    deprecated_method,
39
 
    )
 
37
from bzrlib.symbol_versioning import (deprecated_method, one_four)
40
38
 
41
39
 
42
40
class _SmartStat(object):
54
52
 
55
53
    The connection has a notion of the current directory to which it's
56
54
    connected; this is incorporated in filenames passed to the server.
57
 
 
58
 
    This supports some higher-level RPC operations and can also be treated
 
55
    
 
56
    This supports some higher-level RPC operations and can also be treated 
59
57
    like a Transport to do file-like operations.
60
58
 
61
59
    The connection can be made over a tcp socket, an ssh pipe or a series of
69
67
    # IMPORTANT FOR IMPLEMENTORS: RemoteTransport MUST NOT be given encoding
70
68
    # responsibilities: Put those on SmartClient or similar. This is vital for
71
69
    # the ability to support multiple versions of the smart protocol over time:
72
 
    # RemoteTransport is an adapter from the Transport object model to the
 
70
    # RemoteTransport is an adapter from the Transport object model to the 
73
71
    # SmartClient model, not an encoder.
74
72
 
75
73
    # FIXME: the medium parameter should be private, only the tests requires
92
90
            should only be used for testing purposes; normally this is
93
91
            determined from the medium.
94
92
        """
95
 
        super(RemoteTransport, self).__init__(
96
 
            url, _from_transport=_from_transport)
 
93
        super(RemoteTransport, self).__init__(url,
 
94
                                              _from_transport=_from_transport)
97
95
 
98
96
        # The medium is the connection, except when we need to share it with
99
97
        # other objects (RemoteBzrDir, RemoteRepository etc). In these cases
100
98
        # what we want to share is really the shared connection.
101
99
 
102
 
        if (_from_transport is not None
103
 
            and isinstance(_from_transport, RemoteTransport)):
104
 
            _client = _from_transport._client
105
 
        elif _from_transport is None:
 
100
        if _from_transport is None:
106
101
            # If no _from_transport is specified, we need to intialize the
107
102
            # shared medium.
108
103
            credentials = None
138
133
        # No credentials
139
134
        return None, None
140
135
 
141
 
    def _report_activity(self, bytes, direction):
142
 
        """See Transport._report_activity.
143
 
 
144
 
        Does nothing; the smart medium will report activity triggered by a
145
 
        RemoteTransport.
146
 
        """
147
 
        pass
148
 
 
149
136
    def is_readonly(self):
150
137
        """Smart server transport can do read/write file operations."""
151
138
        try:
168
155
    def get_smart_medium(self):
169
156
        return self._get_connection()
170
157
 
 
158
    @deprecated_method(one_four)
 
159
    def get_shared_medium(self):
 
160
        return self._get_shared_connection()
 
161
 
171
162
    def _remote_path(self, relpath):
172
163
        """Returns the Unicode version of the absolute path for relpath."""
173
164
        return self._combine_paths(self._path, relpath)
181
172
        try:
182
173
            return self._client.call(method, *args)
183
174
        except errors.ErrorFromSmartServer, err:
184
 
            # The first argument, if present, is always a path.
185
 
            if args:
186
 
                context = {'relpath': args[0]}
187
 
            else:
188
 
                context = {}
189
 
            self._translate_error(err, **context)
 
175
            self._translate_error(err)
190
176
 
191
177
    def _call_with_body_bytes(self, method, args, body):
192
178
        """Call a method on the remote server with body bytes."""
193
179
        try:
194
180
            return self._client.call_with_body_bytes(method, args, body)
195
181
        except errors.ErrorFromSmartServer, err:
196
 
            # The first argument, if present, is always a path.
197
 
            if args:
198
 
                context = {'relpath': args[0]}
199
 
            else:
200
 
                context = {}
201
 
            self._translate_error(err, **context)
 
182
            self._translate_error(err)
202
183
 
203
184
    def has(self, relpath):
204
185
        """Indicate whether a remote file of the given name exists or not.
215
196
 
216
197
    def get(self, relpath):
217
198
        """Return file-like object reading the contents of a remote file.
218
 
 
 
199
        
219
200
        :see: Transport.get_bytes()/get_file()
220
201
        """
221
202
        return StringIO(self.get_bytes(relpath))
300
281
 
301
282
    def append_file(self, relpath, from_file, mode=None):
302
283
        return self.append_bytes(relpath, from_file.read(), mode)
303
 
 
 
284
        
304
285
    def append_bytes(self, relpath, bytes, mode=None):
305
286
        resp = self._call_with_body_bytes(
306
287
            'append',
322
303
    def recommended_page_size(self):
323
304
        """Return the recommended page size for this transport."""
324
305
        return 64 * 1024
325
 
 
 
306
        
326
307
    def _readv(self, relpath, offsets):
327
308
        if not offsets:
328
309
            return
332
313
        sorted_offsets = sorted(offsets)
333
314
        coalesced = list(self._coalesce_offsets(sorted_offsets,
334
315
                               limit=self._max_readv_combine,
335
 
                               fudge_factor=self._bytes_to_read_before_seek,
336
 
                               max_size=self._max_readv_bytes))
 
316
                               fudge_factor=self._bytes_to_read_before_seek))
337
317
 
338
318
        # now that we've coallesced things, avoid making enormous requests
339
319
        requests = []
367
347
                    [(c.start, c.length) for c in cur_request])
368
348
                resp, response_handler = result
369
349
            except errors.ErrorFromSmartServer, err:
370
 
                self._translate_error(err, relpath)
 
350
                self._translate_error(err)
371
351
 
372
352
            if resp[0] != 'readv':
373
353
                # This should raise an exception
430
410
    def _ensure_ok(self, resp):
431
411
        if resp[0] != 'ok':
432
412
            raise errors.UnexpectedSmartServerResponse(resp)
433
 
 
434
 
    def _translate_error(self, err, relpath=None):
435
 
        remote._translate_error(err, path=relpath)
 
413
        
 
414
    def _translate_error(self, err, orig_path=None):
 
415
        remote._translate_error(err, path=orig_path)
436
416
 
437
417
    def disconnect(self):
438
418
        self.get_smart_medium().disconnect()
474
454
 
475
455
class RemoteTCPTransport(RemoteTransport):
476
456
    """Connection to smart server over plain tcp.
477
 
 
 
457
    
478
458
    This is essentially just a factory to get 'RemoteTransport(url,
479
459
        SmartTCPClientMedium).
480
460
    """
522
502
 
523
503
class RemoteHTTPTransport(RemoteTransport):
524
504
    """Just a way to connect between a bzr+http:// url and http://.
525
 
 
 
505
    
526
506
    This connection operates slightly differently than the RemoteSSHTransport.
527
507
    It uses a plain http:// transport underneath, which defines what remote
528
508
    .bzr/smart URL we are connected to. From there, all paths that are sent are
577
557
                                   _from_transport=self,
578
558
                                   http_transport=self._http_transport)
579
559
 
580
 
    def _redirected_to(self, source, target):
581
 
        """See transport._redirected_to"""
582
 
        redirected = self._http_transport._redirected_to(source, target)
583
 
        if (redirected is not None
584
 
            and isinstance(redirected, type(self._http_transport))):
585
 
            return RemoteHTTPTransport('bzr+' + redirected.external_url(),
586
 
                                       http_transport=redirected)
587
 
        else:
588
 
            # Either None or a transport for a different protocol
589
 
            return redirected
590
 
 
591
 
 
592
 
class HintingSSHTransport(transport.Transport):
593
 
    """Simple transport that handles ssh:// and points out bzr+ssh://."""
594
 
 
595
 
    def __init__(self, url):
596
 
        raise errors.UnsupportedProtocol(url,
597
 
            'bzr supports bzr+ssh to operate over ssh, use "bzr+%s".' % url)
598
 
 
599
560
 
600
561
def get_test_permutations():
601
562
    """Return (transport, server) permutations for testing."""
602
563
    ### We may need a little more test framework support to construct an
603
564
    ### appropriate RemoteTransport in the future.
604
 
    from bzrlib.tests import test_server
605
 
    return [(RemoteTCPTransport, test_server.SmartTCPServer_for_testing)]
 
565
    from bzrlib.smart import server
 
566
    return [(RemoteTCPTransport, server.SmartTCPServer_for_testing)]