~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/remote.py

  • Committer: John Arbash Meinel
  • Date: 2009-11-18 15:47:16 UTC
  • mto: This revision was merged to the branch mainline in revision 4810.
  • Revision ID: john@arbash-meinel.com-20091118154716-meiszr5ej7ohas3v
Move all the stat comparison and platform checkning code to assertEqualStat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
imported from bzrlib.smart.
21
21
"""
22
22
 
23
 
from __future__ import absolute_import
24
 
 
25
23
__all__ = ['RemoteTransport', 'RemoteTCPTransport', 'RemoteSSHTransport']
26
24
 
27
25
from cStringIO import StringIO
36
34
    urlutils,
37
35
    )
38
36
from bzrlib.smart import client, medium
 
37
from bzrlib.symbol_versioning import (
 
38
    deprecated_method,
 
39
    )
39
40
 
40
41
 
41
42
class _SmartStat(object):
169
170
 
170
171
    def _remote_path(self, relpath):
171
172
        """Returns the Unicode version of the absolute path for relpath."""
172
 
        return urlutils.URL._combine_paths(self._parsed_url.path, relpath)
 
173
        return self._combine_paths(self._path, relpath)
173
174
 
174
175
    def _call(self, method, *args):
175
176
        resp = self._call2(method, *args)
247
248
        transport._file_streams[self.abspath(relpath)] = result
248
249
        return result
249
250
 
250
 
    def put_bytes(self, relpath, raw_bytes, mode=None):
251
 
        if not isinstance(raw_bytes, str):
252
 
            raise TypeError(
253
 
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
254
 
        resp = self._call_with_body_bytes(
255
 
            'put',
 
251
    def put_bytes(self, relpath, upload_contents, mode=None):
 
252
        # FIXME: upload_file is probably not safe for non-ascii characters -
 
253
        # should probably just pass all parameters as length-delimited
 
254
        # strings?
 
255
        if type(upload_contents) is unicode:
 
256
            # Although not strictly correct, we raise UnicodeEncodeError to be
 
257
            # compatible with other transports.
 
258
            raise UnicodeEncodeError(
 
259
                'undefined', upload_contents, 0, 1,
 
260
                'put_bytes must be given bytes, not unicode.')
 
261
        resp = self._call_with_body_bytes('put',
256
262
            (self._remote_path(relpath), self._serialise_optional_mode(mode)),
257
 
            raw_bytes)
 
263
            upload_contents)
258
264
        self._ensure_ok(resp)
259
 
        return len(raw_bytes)
 
265
        return len(upload_contents)
260
266
 
261
 
    def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
 
267
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
262
268
                             create_parent_dir=False,
263
269
                             dir_mode=None):
264
270
        """See Transport.put_bytes_non_atomic."""
271
277
            'put_non_atomic',
272
278
            (self._remote_path(relpath), self._serialise_optional_mode(mode),
273
279
             create_parent_str, self._serialise_optional_mode(dir_mode)),
274
 
            raw_bytes)
 
280
            bytes)
275
281
        self._ensure_ok(resp)
276
282
 
277
283
    def put_file(self, relpath, upload_file, mode=None):
429
435
        remote._translate_error(err, path=relpath)
430
436
 
431
437
    def disconnect(self):
432
 
        m = self.get_smart_medium()
433
 
        if m is not None:
434
 
            m.disconnect()
 
438
        self.get_smart_medium().disconnect()
435
439
 
436
440
    def stat(self, relpath):
437
441
        resp = self._call2('stat', self._remote_path(relpath))
477
481
 
478
482
    def _build_medium(self):
479
483
        client_medium = medium.SmartTCPClientMedium(
480
 
            self._parsed_url.host, self._parsed_url.port, self.base)
 
484
            self._host, self._port, self.base)
481
485
        return client_medium, None
482
486
 
483
487
 
490
494
 
491
495
    def _build_medium(self):
492
496
        client_medium = medium.SmartTCPClientMedium(
493
 
            self._parsed_url.host, self._parsed_url.port, self.base)
 
497
            self._host, self._port, self.base)
494
498
        client_medium._protocol_version = 2
495
499
        client_medium._remember_remote_is_before((1, 6))
496
500
        return client_medium, None
506
510
    def _build_medium(self):
507
511
        location_config = config.LocationConfig(self.base)
508
512
        bzr_remote_path = location_config.get_bzr_remote_path()
509
 
        user = self._parsed_url.user
 
513
        user = self._user
510
514
        if user is None:
511
515
            auth = config.AuthenticationConfig()
512
 
            user = auth.get_user('ssh', self._parsed_url.host,
513
 
                self._parsed_url.port)
514
 
        ssh_params = medium.SSHParams(self._parsed_url.host,
515
 
                self._parsed_url.port, user, self._parsed_url.password,
516
 
                bzr_remote_path)
517
 
        client_medium = medium.SmartSSHClientMedium(self.base, ssh_params)
518
 
        return client_medium, (user, self._parsed_url.password)
 
516
            user = auth.get_user('ssh', self._host, self._port)
 
517
        client_medium = medium.SmartSSHClientMedium(self._host, self._port,
 
518
            user, self._password, self.base,
 
519
            bzr_remote_path=bzr_remote_path)
 
520
        return client_medium, (user, self._password)
519
521
 
520
522
 
521
523
class RemoteHTTPTransport(RemoteTransport):
535
537
            # url only for an intial construction (when the url came from the
536
538
            # command-line).
537
539
            http_url = base[len('bzr+'):]
538
 
            self._http_transport = transport.get_transport_from_url(http_url)
 
540
            self._http_transport = transport.get_transport(http_url)
539
541
        else:
540
542
            self._http_transport = http_transport
541
543
        super(RemoteHTTPTransport, self).__init__(
599
601
    """Return (transport, server) permutations for testing."""
600
602
    ### We may need a little more test framework support to construct an
601
603
    ### appropriate RemoteTransport in the future.
602
 
    from bzrlib.tests import test_server
603
 
    return [(RemoteTCPTransport, test_server.SmartTCPServer_for_testing)]
 
604
    from bzrlib.smart import server
 
605
    return [(RemoteTCPTransport, server.SmartTCPServer_for_testing)]