~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

Add a NEWS entry and prepare submission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
22
22
from cStringIO import StringIO
23
23
import struct
24
24
import sys
25
 
import thread
26
25
import threading
27
26
import time
28
27
 
62
61
 
63
62
def _encode_tuple(args):
64
63
    """Encode the tuple args to a bytestream."""
65
 
    joined = '\x01'.join(args) + '\n'
66
 
    if type(joined) is unicode:
67
 
        # XXX: We should fix things so this never happens!  -AJB, 20100304
68
 
        mutter('response args contain unicode, should be only bytes: %r',
69
 
               joined)
70
 
        joined = joined.encode('ascii')
71
 
    return joined
 
64
    return '\x01'.join(args) + '\n'
72
65
 
73
66
 
74
67
class Requester(object):
1073
1066
class _ProtocolThreeEncoder(object):
1074
1067
 
1075
1068
    response_marker = request_marker = MESSAGE_VERSION_THREE
1076
 
    BUFFER_SIZE = 1024*1024 # 1 MiB buffer before flushing
1077
1069
 
1078
1070
    def __init__(self, write_func):
1079
1071
        self._buf = []
1080
 
        self._buf_len = 0
1081
1072
        self._real_write_func = write_func
1082
1073
 
1083
1074
    def _write_func(self, bytes):
1090
1081
        #       Note that osutils.send_all always sends 64kB chunks anyway, so
1091
1082
        #       we might just push out smaller bits at a time?
1092
1083
        self._buf.append(bytes)
1093
 
        self._buf_len += len(bytes)
1094
 
        if self._buf_len > self.BUFFER_SIZE:
 
1084
        if len(self._buf) > 100:
1095
1085
            self.flush()
1096
1086
 
1097
1087
    def flush(self):
1098
1088
        if self._buf:
1099
1089
            self._real_write_func(''.join(self._buf))
1100
1090
            del self._buf[:]
1101
 
            self._buf_len = 0
1102
1091
 
1103
1092
    def _serialise_offsets(self, offsets):
1104
1093
        """Serialise a readv offset list."""
1154
1143
        self.response_sent = False
1155
1144
        self._headers = {'Software version': bzrlib.__version__}
1156
1145
        if 'hpss' in debug.debug_flags:
1157
 
            self._thread_id = thread.get_ident()
 
1146
            self._thread_id = threading.currentThread().get_ident()
1158
1147
            self._response_start_time = None
1159
1148
 
1160
1149
    def _trace(self, action, message, extra_bytes=None, include_time=False):