~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-17 08:59:19 UTC
  • mfrom: (5037.2.1 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100217085919-23vc62bvq8848q65
(mbp) rest markup fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 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
18
18
client and server.
19
19
"""
20
20
 
21
 
from __future__ import absolute_import
22
 
 
23
21
import collections
24
22
from cStringIO import StringIO
25
23
import struct
26
24
import sys
27
25
import thread
 
26
import threading
28
27
import time
29
28
 
30
29
import bzrlib
63
62
 
64
63
def _encode_tuple(args):
65
64
    """Encode the tuple args to a bytestream."""
66
 
    joined = '\x01'.join(args) + '\n'
67
 
    if type(joined) is unicode:
68
 
        # XXX: We should fix things so this never happens!  -AJB, 20100304
69
 
        mutter('response args contain unicode, should be only bytes: %r',
70
 
               joined)
71
 
        joined = joined.encode('ascii')
72
 
    return joined
 
65
    return '\x01'.join(args) + '\n'
73
66
 
74
67
 
75
68
class Requester(object):
655
648
        """Make a remote call with a readv array.
656
649
 
657
650
        The body is encoded with one line per readv offset pair. The numbers in
658
 
        each pair are separated by a comma, and no trailing \\n is emitted.
 
651
        each pair are separated by a comma, and no trailing \n is emitted.
659
652
        """
660
653
        if 'hpss' in debug.debug_flags:
661
654
            mutter('hpss call w/readv: %s', repr(args)[1:-1])
1082
1075
        self._real_write_func = write_func
1083
1076
 
1084
1077
    def _write_func(self, bytes):
 
1078
        # TODO: It is probably more appropriate to use sum(map(len, _buf))
 
1079
        #       for total number of bytes to write, rather than buffer based on
 
1080
        #       the number of write() calls
1085
1081
        # TODO: Another possibility would be to turn this into an async model.
1086
1082
        #       Where we let another thread know that we have some bytes if
1087
1083
        #       they want it, but we don't actually block for it
1229
1225
                    if first_chunk is None:
1230
1226
                        first_chunk = chunk
1231
1227
                    self._write_prefixed_body(chunk)
1232
 
                    self.flush()
1233
1228
                    if 'hpssdetail' in debug.debug_flags:
1234
1229
                        # Not worth timing separately, as _write_func is
1235
1230
                        # actually buffered
1290
1285
        _ProtocolThreeEncoder.__init__(self, medium_request.accept_bytes)
1291
1286
        self._medium_request = medium_request
1292
1287
        self._headers = {}
1293
 
        self.body_stream_started = None
1294
1288
 
1295
1289
    def set_headers(self, headers):
1296
1290
        self._headers = headers.copy()
1331
1325
        """Make a remote call with a readv array.
1332
1326
 
1333
1327
        The body is encoded with one line per readv offset pair. The numbers in
1334
 
        each pair are separated by a comma, and no trailing \\n is emitted.
 
1328
        each pair are separated by a comma, and no trailing \n is emitted.
1335
1329
        """
1336
1330
        if 'hpss' in debug.debug_flags:
1337
1331
            mutter('hpss call w/readv: %s', repr(args)[1:-1])
1356
1350
            if path is not None:
1357
1351
                mutter('                  (to %s)', path)
1358
1352
            self._request_start_time = osutils.timer_func()
1359
 
        self.body_stream_started = False
1360
1353
        self._write_protocol_version()
1361
1354
        self._write_headers(self._headers)
1362
1355
        self._write_structure(args)
1364
1357
        #       have finished sending the stream.  We would notice at the end
1365
1358
        #       anyway, but if the medium can deliver it early then it's good
1366
1359
        #       to short-circuit the whole request...
1367
 
        # Provoke any ConnectionReset failures before we start the body stream.
1368
 
        self.flush()
1369
 
        self.body_stream_started = True
1370
1360
        for exc_info, part in _iter_with_errors(stream):
1371
1361
            if exc_info is not None:
1372
1362
                # Iterating the stream failed.  Cleanly abort the request.