~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/message.py

  • Committer: Frank Aspell
  • Date: 2009-02-22 16:54:02 UTC
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: frankaspell@googlemail.com-20090222165402-2myrucnu7er5w4ha
Fixing various typos

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import collections
18
18
from cStringIO import StringIO
36
36
 
37
37
    def headers_received(self, headers):
38
38
        """Called when message headers are received.
39
 
 
 
39
        
40
40
        This default implementation just stores them in self.headers.
41
41
        """
42
42
        self.headers = headers
67
67
 
68
68
    def protocol_error(self, exception):
69
69
        """Called when there is a protocol decoding error.
70
 
 
 
70
        
71
71
        The default implementation just re-raises the exception.
72
72
        """
73
73
        raise
74
 
 
 
74
    
75
75
    def end_received(self):
76
76
        """Called when the end of the message is received."""
77
77
        # No-op by default.
134
134
 
135
135
    def _args_received(self, args):
136
136
        self.expecting = 'body'
137
 
        self.request_handler.args_received(args)
 
137
        self.request_handler.dispatch_command(args[0], args[1:])
138
138
        if self.request_handler.finished_reading:
139
139
            self._response_sent = True
140
140
            self.responder.send_response(self.request_handler.response)
172
172
 
173
173
    def read_response_tuple(self, expect_body=False):
174
174
        """Reads and returns the response tuple for the current request.
175
 
 
 
175
        
176
176
        :keyword expect_body: a boolean indicating if a body is expected in the
177
177
            response.  Some protocol versions needs this information to know
178
178
            when a response is finished.  If False, read_body_bytes should
283
283
                    self._protocol_decoder._get_in_buffer()[:10],
284
284
                    self._protocol_decoder.state_accept.__name__)
285
285
            raise errors.ConnectionReset(
286
 
                "Unexpected end of message. "
287
 
                "Please check connectivity and permissions, and report a bug "
288
 
                "if problems persist.")
 
286
                "please check connectivity and permissions",
 
287
                "(and try -Dhpss if further diagnosis is required)")
289
288
        self._protocol_decoder.accept_bytes(bytes)
290
289
 
291
290
    def protocol_error(self, exception):
293
292
        self.finished_reading = True
294
293
        self._medium_request.finished_reading()
295
294
        raise
296
 
 
 
295
        
297
296
    def read_response_tuple(self, expect_body=False):
298
297
        """Read a response tuple from the wire."""
299
298
        self._wait_for_response_args()
308
307
 
309
308
    def read_body_bytes(self, count=-1):
310
309
        """Read bytes from the body, decoding into a byte stream.
311
 
 
312
 
        We read all bytes at once to ensure we've checked the trailer for
 
310
        
 
311
        We read all bytes at once to ensure we've checked the trailer for 
313
312
        errors, and then feed the buffer back as read_body_bytes is called.
314
313
 
315
314
        Like the builtin file.read in Python, a count of -1 (the default) means
330
329
        while not self.finished_reading:
331
330
            while self._bytes_parts:
332
331
                bytes_part = self._bytes_parts.popleft()
333
 
                if 'hpssdetail' in debug.debug_flags:
 
332
                if 'hpss' in debug.debug_flags:
334
333
                    mutter('              %d byte part read', len(bytes_part))
335
334
                yield bytes_part
336
335
            self._read_more()
353
352
        raise errors.LockContention('(remote lock)')
354
353
    elif error_name == 'LockFailed':
355
354
        raise errors.LockFailed(*error_args[:2])
356
 
    elif error_name == 'FileExists':
357
 
        raise errors.FileExists(error_args[0])
358
 
    elif error_name == 'NoSuchFile':
359
 
        raise errors.NoSuchFile(error_args[0])
360
355
    else:
361
356
        raise errors.ErrorFromSmartServer(error_tuple)