339 self._data.append(self._item) |
340 self._data.append(self._item) |
340 def end(self): |
341 def end(self): |
341 baseformatter.end(self) |
342 baseformatter.end(self) |
342 self._out.write(pickle.dumps(self._data)) |
343 self._out.write(pickle.dumps(self._data)) |
343 |
344 |
|
345 class cborformatter(baseformatter): |
|
346 '''serialize items as an indefinite-length CBOR array''' |
|
347 def __init__(self, ui, out, topic, opts): |
|
348 baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
|
349 self._out = out |
|
350 self._out.write(cborutil.BEGIN_INDEFINITE_ARRAY) |
|
351 def _showitem(self): |
|
352 self._out.write(b''.join(cborutil.streamencode(self._item))) |
|
353 def end(self): |
|
354 baseformatter.end(self) |
|
355 self._out.write(cborutil.BREAK) |
|
356 |
344 class jsonformatter(baseformatter): |
357 class jsonformatter(baseformatter): |
345 def __init__(self, ui, out, topic, opts): |
358 def __init__(self, ui, out, topic, opts): |
346 baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
359 baseformatter.__init__(self, ui, topic, opts, _nullconverter) |
347 self._out = out |
360 self._out = out |
348 self._out.write("[") |
361 self._out.write("[") |
615 'fctx': _loadfctx, |
628 'fctx': _loadfctx, |
616 } |
629 } |
617 |
630 |
618 def formatter(ui, out, topic, opts): |
631 def formatter(ui, out, topic, opts): |
619 template = opts.get("template", "") |
632 template = opts.get("template", "") |
620 if template == "json": |
633 if template == "cbor": |
|
634 return cborformatter(ui, out, topic, opts) |
|
635 elif template == "json": |
621 return jsonformatter(ui, out, topic, opts) |
636 return jsonformatter(ui, out, topic, opts) |
622 elif template == "pickle": |
637 elif template == "pickle": |
623 return pickleformatter(ui, out, topic, opts) |
638 return pickleformatter(ui, out, topic, opts) |
624 elif template == "debug": |
639 elif template == "debug": |
625 return debugformatter(ui, out, topic, opts) |
640 return debugformatter(ui, out, topic, opts) |