~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-03 08:49:38 UTC
  • mfrom: (3111.1.31 175524)
  • mto: This revision was merged to the branch mainline in revision 3158.
  • Revision ID: v.ladeuil+lp@free.fr-20080103084938-7kvurk5uvde2ui54
Fix bug #175524, http test servers are 1.1 compliant

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import socket
29
29
import sys
30
30
 
31
 
from bzrlib import errors
 
31
from bzrlib import (
 
32
    errors,
 
33
    osutils,
 
34
    symbol_versioning,
 
35
    )
32
36
from bzrlib.smart.protocol import (
33
37
    REQUEST_VERSION_TWO,
34
38
    SmartServerRequestProtocolOne,
35
39
    SmartServerRequestProtocolTwo,
36
40
    )
37
 
 
38
 
try:
39
 
    from bzrlib.transport import ssh
40
 
except errors.ParamikoNotPresent:
41
 
    # no paramiko.  SmartSSHClientMedium will break.
42
 
    pass
 
41
from bzrlib.transport import ssh
43
42
 
44
43
 
45
44
class SmartServerStreamMedium(object):
179
178
        self.finished = True
180
179
 
181
180
    def _write_out(self, bytes):
182
 
        self.socket.sendall(bytes)
 
181
        osutils.send_all(self.socket, bytes)
183
182
 
184
183
 
185
184
class SmartServerPipeStreamMedium(SmartServerStreamMedium):
443
442
    """A client medium using SSH."""
444
443
    
445
444
    def __init__(self, host, port=None, username=None, password=None,
446
 
            vendor=None):
 
445
            vendor=None, bzr_remote_path=None):
447
446
        """Creates a client that will connect on the first use.
448
447
        
449
448
        :param vendor: An optional override for the ssh vendor to use. See
459
458
        self._ssh_connection = None
460
459
        self._vendor = vendor
461
460
        self._write_to = None
 
461
        self._bzr_remote_path = bzr_remote_path
 
462
        if self._bzr_remote_path is None:
 
463
            symbol_versioning.warn(
 
464
                'bzr_remote_path is required as of bzr 0.92',
 
465
                DeprecationWarning, stacklevel=2)
 
466
            self._bzr_remote_path = os.environ.get('BZR_REMOTE_PATH', 'bzr')
462
467
 
463
468
    def _accept_bytes(self, bytes):
464
469
        """See SmartClientStreamMedium.accept_bytes."""
478
483
        """Connect this medium if not already connected."""
479
484
        if self._connected:
480
485
            return
481
 
        executable = os.environ.get('BZR_REMOTE_PATH', 'bzr')
482
486
        if self._vendor is None:
483
487
            vendor = ssh._get_ssh_vendor()
484
488
        else:
485
489
            vendor = self._vendor
486
490
        self._ssh_connection = vendor.connect_ssh(self._username,
487
491
                self._password, self._host, self._port,
488
 
                command=[executable, 'serve', '--inet', '--directory=/',
489
 
                         '--allow-writes'])
 
492
                command=[self._bzr_remote_path, 'serve', '--inet',
 
493
                         '--directory=/', '--allow-writes'])
490
494
        self._read_from, self._write_to = \
491
495
            self._ssh_connection.get_filelike_channels()
492
496
        self._connected = True
502
506
        return self._read_from.read(count)
503
507
 
504
508
 
 
509
# Port 4155 is the default port for bzr://, registered with IANA.
 
510
BZR_DEFAULT_INTERFACE = '0.0.0.0'
 
511
BZR_DEFAULT_PORT = 4155
 
512
 
 
513
 
505
514
class SmartTCPClientMedium(SmartClientStreamMedium):
506
515
    """A client medium using TCP."""
507
516
    
516
525
    def _accept_bytes(self, bytes):
517
526
        """See SmartClientMedium.accept_bytes."""
518
527
        self._ensure_connection()
519
 
        self._socket.sendall(bytes)
 
528
        osutils.send_all(self._socket, bytes)
520
529
 
521
530
    def disconnect(self):
522
531
        """See SmartClientMedium.disconnect()."""
532
541
            return
533
542
        self._socket = socket.socket()
534
543
        self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
535
 
        result = self._socket.connect_ex((self._host, int(self._port)))
 
544
        if self._port is None:
 
545
            port = BZR_DEFAULT_PORT
 
546
        else:
 
547
            port = int(self._port)
 
548
        result = self._socket.connect_ex((self._host, port))
536
549
        if result:
537
550
            raise errors.ConnectionError("failed to connect to %s:%d: %s" %
538
 
                    (self._host, self._port, os.strerror(result)))
 
551
                    (self._host, port, os.strerror(result)))
539
552
        self._connected = True
540
553
 
541
554
    def _flush(self):