/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/protocol.py

  • Committer: Jelmer Vernooij
  • Date: 2017-02-05 17:00:29 UTC
  • mto: (6621.2.1 py3)
  • mto: This revision was merged to the branch mainline in revision 6624.
  • Revision ID: jelmer@jelmer.uk-20170205170029-s01xdro0hkixhq3r
Convert some octal numbers to new notations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
client and server.
19
19
"""
20
20
 
 
21
from __future__ import absolute_import
 
22
 
21
23
import collections
22
24
from cStringIO import StringIO
23
25
import struct
24
26
import sys
25
27
import thread
26
 
import threading
27
28
import time
28
29
 
29
30
import bzrlib
167
168
                    self._send_response(self.request.response)
168
169
            except KeyboardInterrupt:
169
170
                raise
170
 
            except errors.UnknownSmartMethod, err:
 
171
            except errors.UnknownSmartMethod as err:
171
172
                protocol_error = errors.SmartProtocolError(
172
173
                    "bad request %r" % (err.verb,))
173
174
                failure = request.FailedSmartServerResponse(
174
175
                    ('error', str(protocol_error)))
175
176
                self._send_response(failure)
176
177
                return
177
 
            except Exception, exception:
 
178
            except Exception as exception:
178
179
                # everything else: pass to client, flush, and quit
179
180
                log_exception_quietly()
180
181
                self._send_response(request.FailedSmartServerResponse(
408
409
                #     _NeedMoreBytes).
409
410
                current_state = self.state_accept
410
411
                self.state_accept()
411
 
        except _NeedMoreBytes, e:
 
412
        except _NeedMoreBytes as e:
412
413
            self._number_needed_bytes = e.count
413
414
 
414
415
 
654
655
        """Make a remote call with a readv array.
655
656
 
656
657
        The body is encoded with one line per readv offset pair. The numbers in
657
 
        each pair are separated by a comma, and no trailing \n is emitted.
 
658
        each pair are separated by a comma, and no trailing \\n is emitted.
658
659
        """
659
660
        if 'hpss' in debug.debug_flags:
660
661
            mutter('hpss call w/readv: %s', repr(args)[1:-1])
907
908
            _StatefulDecoder.accept_bytes(self, bytes)
908
909
        except KeyboardInterrupt:
909
910
            raise
910
 
        except errors.SmartMessageHandlerError, exception:
 
911
        except errors.SmartMessageHandlerError as exception:
911
912
            # We do *not* set self.decoding_failed here.  The message handler
912
913
            # has raised an error, but the decoder is still able to parse bytes
913
914
            # and determine when this message ends.
918
919
            # exception has interrupted the loop that runs the state machine.
919
920
            # So we call accept_bytes again to restart it.
920
921
            self.accept_bytes('')
921
 
        except Exception, exception:
 
922
        except Exception as exception:
922
923
            # The decoder itself has raised an exception.  We cannot continue
923
924
            # decoding.
924
925
            self.decoding_failed = True
1081
1082
        self._real_write_func = write_func
1082
1083
 
1083
1084
    def _write_func(self, bytes):
1084
 
        # TODO: It is probably more appropriate to use sum(map(len, _buf))
1085
 
        #       for total number of bytes to write, rather than buffer based on
1086
 
        #       the number of write() calls
1087
1085
        # TODO: Another possibility would be to turn this into an async model.
1088
1086
        #       Where we let another thread know that we have some bytes if
1089
1087
        #       they want it, but we don't actually block for it
1231
1229
                    if first_chunk is None:
1232
1230
                        first_chunk = chunk
1233
1231
                    self._write_prefixed_body(chunk)
 
1232
                    self.flush()
1234
1233
                    if 'hpssdetail' in debug.debug_flags:
1235
1234
                        # Not worth timing separately, as _write_func is
1236
1235
                        # actually buffered
1291
1290
        _ProtocolThreeEncoder.__init__(self, medium_request.accept_bytes)
1292
1291
        self._medium_request = medium_request
1293
1292
        self._headers = {}
 
1293
        self.body_stream_started = None
1294
1294
 
1295
1295
    def set_headers(self, headers):
1296
1296
        self._headers = headers.copy()
1331
1331
        """Make a remote call with a readv array.
1332
1332
 
1333
1333
        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.
 
1334
        each pair are separated by a comma, and no trailing \\n is emitted.
1335
1335
        """
1336
1336
        if 'hpss' in debug.debug_flags:
1337
1337
            mutter('hpss call w/readv: %s', repr(args)[1:-1])
1356
1356
            if path is not None:
1357
1357
                mutter('                  (to %s)', path)
1358
1358
            self._request_start_time = osutils.timer_func()
 
1359
        self.body_stream_started = False
1359
1360
        self._write_protocol_version()
1360
1361
        self._write_headers(self._headers)
1361
1362
        self._write_structure(args)
1363
1364
        #       have finished sending the stream.  We would notice at the end
1364
1365
        #       anyway, but if the medium can deliver it early then it's good
1365
1366
        #       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
1366
1370
        for exc_info, part in _iter_with_errors(stream):
1367
1371
            if exc_info is not None:
1368
1372
                # Iterating the stream failed.  Cleanly abort the request.