From 904116553df1ac3d3ef5ecc88df33d04be29cf50 Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Fri, 14 Nov 2014 13:23:12 +0100 Subject: format: make passing protocol/protodecl optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is usually not used internally to allow "1 function, more roles" anyway. Signed-off-by: Jan Pokorný --- format.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'format.py') diff --git a/format.py b/format.py index 736141a..6fe0f2f 100644 --- a/format.py +++ b/format.py @@ -337,13 +337,14 @@ class SimpleFormat(Format): super(SimpleFormat, self).__init__(protocol, *args, **kwargs) @Format.producing(BYTESTRING) - def get_bytestring(self, protocol): + def get_bytestring(self, *protodecl): if self.FILE in self._representations: # break the possible loop with file(self.FILE(), 'rb') as f: return f.read() @Format.producing(FILE) - def get_file(self, protocol, outfile): + def get_file(self, *protodecl): + outfile = protodecl[-1] if hasattr(outfile, 'write'): # assume fileobj out of our control, do not close outfile.write(self.BYTESTRING()) @@ -729,7 +730,7 @@ class XML(SimpleFormat): etree_validator = etree_rng_validator @SimpleFormat.producing(BYTESTRING, chained=True) - def get_bytestring(self, protocol): + def get_bytestring(self, *protodecl): # chained fallback return etree.tostring(self.ETREE(protect_safe=True), pretty_print=True) @@ -737,5 +738,5 @@ class XML(SimpleFormat): @SimpleFormat.producing(ETREE, protect=True, # pre 2.7 compat: http://bugs.python.org/issue5982 validator=etree_validator.__get__(1).im_func) - def get_etree(self, protocol): + def get_etree(self, *protodecl): return etree.fromstring(self.BYTESTRING()).getroottree() -- cgit