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

  • Committer: John Arbash Meinel
  • Date: 2009-12-21 17:24:22 UTC
  • mfrom: (4913 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4916.
  • Revision ID: john@arbash-meinel.com-20091221172422-0zy2v8x3fhcdc8c0
Merge bzr.dev 4913, to put NEWS in its place.

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