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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Ping plugin for brz."""
18
 
 
19
 
from ...commands import Command
20
 
from ...lazy_import import lazy_import
 
17
"""Ping plugin for bzr."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from brzlib.commands import Command
 
22
from brzlib.lazy_import import lazy_import
21
23
 
22
24
lazy_import(globals(), """
23
 
from breezy.bzr.smart.client import _SmartClient
24
 
from breezy.transport import get_transport
 
25
from brzlib import errors
 
26
from brzlib.smart.client import _SmartClient
 
27
from brzlib.transport import get_transport
25
28
""")
26
29
 
27
 
from breezy import errors
28
 
 
29
30
 
30
31
class cmd_ping(Command):
31
32
    """Pings a Bazaar smart server.
32
 
 
33
 
    This command sends a 'hello' request to the given location using the brz
 
33
    
 
34
    This command sends a 'hello' request to the given location using the bzr
34
35
    smart protocol, and reports the response.
35
36
    """
36
37
 
40
41
        transport = get_transport(location)
41
42
        try:
42
43
            medium = transport.get_smart_medium()
43
 
        except errors.NoSmartMedium as e:
 
44
        except errors.NoSmartMedium, e:
44
45
            raise errors.BzrCommandError(str(e))
45
46
        client = _SmartClient(medium)
46
47
        # Use call_expecting_body (even though we don't expect a body) so that
47
48
        # we can see the response headers (if any) via the handler object.
48
 
        response, handler = client.call_expecting_body(b'hello')
 
49
        response, handler = client.call_expecting_body('hello')
49
50
        handler.cancel_read_body()
50
51
        self.outf.write('Response: %r\n' % (response,))
51
52
        if getattr(handler, 'headers', None) is not None:
52
 
            headers = {
53
 
                k.decode('utf-8'): v.decode('utf-8')
54
 
                for (k, v) in handler.headers.items()}
55
 
            self.outf.write('Headers: %r\n' % (headers,))
 
53
            self.outf.write('Headers: %r\n' % (handler.headers,))