Mercurial > public > mercurial-scm > hg-stable
diff mercurial/formatter.py @ 22430:968247e8f4ac
formatter: add pickle format
This gives convenient Python2 output. Python 3 users will need encoding=bytes.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 12 Sep 2014 18:36:38 -0500 |
parents | 427e80a18ef8 |
children | 2642ce9be6ef |
line wrap: on
line diff
--- a/mercurial/formatter.py Mon Sep 15 13:15:07 2014 -0500 +++ b/mercurial/formatter.py Fri Sep 12 18:36:38 2014 -0500 @@ -5,6 +5,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +import cPickle from i18n import _ import encoding, util @@ -77,6 +78,16 @@ baseformatter.end(self) self._ui.write("]\n") +class pickleformatter(baseformatter): + def __init__(self, ui, topic, opts): + baseformatter.__init__(self, ui, topic, opts) + self._data = [] + def _showitem(self): + self._data.append(self._item) + def end(self): + baseformatter.end(self) + self._ui.write(cPickle.dumps(self._data)) + class jsonformatter(baseformatter): def __init__(self, ui, topic, opts): baseformatter.__init__(self, ui, topic, opts) @@ -108,6 +119,8 @@ template = opts.get("template", "") if template == "json": return jsonformatter(ui, topic, opts) + elif template == "pickle": + return pickleformatter(ui, topic, opts) elif template == "debug": return debugformatter(ui, topic, opts) elif template != "":