/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/smart/medium.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-27 06:10:18 UTC
  • mfrom: (3309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080327061018-dxztpxyv6yoeg3am
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    )
36
36
from bzrlib.smart.protocol import (
37
37
    REQUEST_VERSION_TWO,
 
38
    SmartClientRequestProtocolOne,
38
39
    SmartServerRequestProtocolOne,
39
40
    SmartServerRequestProtocolTwo,
40
41
    )
361
362
            new_char = self.read_bytes(1)
362
363
            line += new_char
363
364
            if new_char == '':
364
 
                raise errors.SmartProtocolError(
365
 
                    'unexpected end of file reading from server')
 
365
                # end of file encountered reading from server
 
366
                raise errors.ConnectionReset(
 
367
                    "please check connectivity and permissions",
 
368
                    "(and try -Dhpss if further diagnosis is required)")
366
369
        return line
367
370
 
368
371
 
369
372
class SmartClientMedium(object):
370
373
    """Smart client is a medium for sending smart protocol requests over."""
371
374
 
 
375
    def __init__(self):
 
376
        super(SmartClientMedium, self).__init__()
 
377
        self._protocol_version_error = None
 
378
        self._protocol_version = None
 
379
 
 
380
    def protocol_version(self):
 
381
        """Find out the best protocol version to use."""
 
382
        if self._protocol_version_error is not None:
 
383
            raise self._protocol_version_error
 
384
        if self._protocol_version is None:
 
385
            try:
 
386
                medium_request = self.get_request()
 
387
                # Send a 'hello' request in protocol version one, for maximum
 
388
                # backwards compatibility.
 
389
                client_protocol = SmartClientRequestProtocolOne(medium_request)
 
390
                self._protocol_version = client_protocol.query_version()
 
391
            except errors.SmartProtocolError, e:
 
392
                # Cache the error, just like we would cache a successful
 
393
                # result.
 
394
                self._protocol_version_error = e
 
395
                raise
 
396
        return self._protocol_version
 
397
 
372
398
    def disconnect(self):
373
399
        """If this medium maintains a persistent connection, close it.
374
400
        
386
412
    """
387
413
 
388
414
    def __init__(self):
 
415
        SmartClientMedium.__init__(self)
389
416
        self._current_request = None
 
417
        # Be optimistic: we assume the remote end can accept new remote
 
418
        # requests until we get an error saying otherwise.  (1.2 adds some
 
419
        # requests that send bodies, which confuses older servers.)
 
420
        self._remote_is_at_least_1_2 = True
390
421
 
391
422
    def accept_bytes(self, bytes):
392
423
        self._accept_bytes(bytes)
548
579
            port = BZR_DEFAULT_PORT
549
580
        else:
550
581
            port = int(self._port)
551
 
        result = self._socket.connect_ex((self._host, port))
552
 
        if result:
 
582
        try:
 
583
            self._socket.connect((self._host, port))
 
584
        except socket.error, err:
 
585
            # socket errors either have a (string) or (errno, string) as their
 
586
            # args.
 
587
            if type(err.args) is str:
 
588
                err_msg = err.args
 
589
            else:
 
590
                err_msg = err.args[1]
553
591
            raise errors.ConnectionError("failed to connect to %s:%d: %s" %
554
 
                    (self._host, port, os.strerror(result)))
 
592
                    (self._host, port, err_msg))
555
593
        self._connected = True
556
594
 
557
595
    def _flush(self):