~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

  • Committer: Robert Collins
  • Date: 2009-12-15 23:28:24 UTC
  • mfrom: (4900 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4920.
  • Revision ID: robertc@robertcollins.net-20091215232824-yewvn7pn7baaevux
Merge trunk, resolving NEWS conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
from bzrlib import (
38
38
    bzrdir,
 
39
    debug,
39
40
    errors,
 
41
    osutils,
40
42
    registry,
41
43
    revision,
42
44
    trace,
287
289
        self.response = None
288
290
        self.finished_reading = False
289
291
        self._command = None
 
292
        if 'hpss' in debug.debug_flags:
 
293
            self._request_start_time = osutils.timer_func()
 
294
            self._thread_id = threading.currentThread().get_ident()
 
295
 
 
296
    def _trace(self, action, message, extra_bytes=None, include_time=False):
 
297
        # It is a bit of a shame that this functionality overlaps with that of 
 
298
        # ProtocolThreeRequester._trace. However, there is enough difference
 
299
        # that just putting it in a helper doesn't help a lot. And some state
 
300
        # is taken from the instance.
 
301
        if include_time:
 
302
            t = '%5.3fs ' % (osutils.timer_func() - self._request_start_time)
 
303
        else:
 
304
            t = ''
 
305
        if extra_bytes is None:
 
306
            extra = ''
 
307
        else:
 
308
            extra = ' ' + repr(extra_bytes[:40])
 
309
            if len(extra) > 33:
 
310
                extra = extra[:29] + extra[-1] + '...'
 
311
        trace.mutter('%12s: [%s] %s%s%s'
 
312
                     % (action, self._thread_id, t, message, extra))
290
313
 
291
314
    def accept_body(self, bytes):
292
315
        """Accept body data."""
294
317
            # no active command object, so ignore the event.
295
318
            return
296
319
        self._run_handler_code(self._command.do_chunk, (bytes,), {})
 
320
        if 'hpss' in debug.debug_flags:
 
321
            self._trace('accept body',
 
322
                        '%d bytes' % (len(bytes),), bytes)
297
323
 
298
324
    def end_of_body(self):
299
325
        """No more body data will be received."""
300
326
        self._run_handler_code(self._command.do_end, (), {})
301
327
        # cannot read after this.
302
328
        self.finished_reading = True
 
329
        if 'hpss' in debug.debug_flags:
 
330
            self._trace('end of body', '', include_time=True)
303
331
 
304
332
    def _run_handler_code(self, callable, args, kwargs):
305
333
        """Run some handler specific code 'callable'.
334
362
 
335
363
    def headers_received(self, headers):
336
364
        # Just a no-op at the moment.
337
 
        pass
 
365
        if 'hpss' in debug.debug_flags:
 
366
            self._trace('headers', repr(headers))
338
367
 
339
368
    def args_received(self, args):
340
369
        cmd = args[0]
342
371
        try:
343
372
            command = self._commands.get(cmd)
344
373
        except LookupError:
 
374
            if 'hpss' in debug.debug_flags:
 
375
                self._trace('hpss unknown request', 
 
376
                            cmd, repr(args)[1:-1])
345
377
            raise errors.UnknownSmartMethod(cmd)
 
378
        if 'hpss' in debug.debug_flags:
 
379
            from bzrlib.smart import vfs
 
380
            if issubclass(command, vfs.VfsRequest):
 
381
                action = 'hpss vfs req'
 
382
            else:
 
383
                action = 'hpss request'
 
384
            self._trace(action, 
 
385
                        '%s %s' % (cmd, repr(args)[1:-1]))
346
386
        self._command = command(
347
387
            self._backing_transport, self._root_client_path, self._jail_root)
348
388
        self._run_handler_code(self._command.execute, args, {})
352
392
            # no active command object, so ignore the event.
353
393
            return
354
394
        self._run_handler_code(self._command.do_end, (), {})
 
395
        if 'hpss' in debug.debug_flags:
 
396
            self._trace('end', '', include_time=True)
355
397
 
356
398
    def post_body_error_received(self, error_args):
357
399
        # Just a no-op at the moment.