summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-11-14 13:23:12 +0100
committerJan Pokorný <jpokorny@redhat.com>2014-11-14 22:11:19 +0100
commit904116553df1ac3d3ef5ecc88df33d04be29cf50 (patch)
tree64e66d0f3ce5d1dd52c714979076e7089b8392c9
parent79360db8e405d520379027cc73c02b08f28b1fc0 (diff)
downloadclufter-904116553df1ac3d3ef5ecc88df33d04be29cf50.tar.gz
clufter-904116553df1ac3d3ef5ecc88df33d04be29cf50.tar.xz
clufter-904116553df1ac3d3ef5ecc88df33d04be29cf50.zip
format: make passing protocol/protodecl optional
It is usually not used internally to allow "1 function, more roles" anyway. Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--format.py9
-rw-r--r--formats/command.py6
-rw-r--r--formats/simpleconfig.py4
3 files changed, 10 insertions, 9 deletions
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()
diff --git a/formats/command.py b/formats/command.py
index 6613dde..f38897a 100644
--- a/formats/command.py
+++ b/formats/command.py
@@ -16,7 +16,7 @@ class command(SimpleFormat):
MERGED = Protocol('merged')
@SimpleFormat.producing(BYTESTRING)
- def get_bytestring(self, protocol):
+ def get_bytestring(self, *protodecl):
"""Return command as canonical single string"""
# try to look (indirectly) if we have a file at hand first
ret = super(command, self).get_bytestring(self.BYTESTRING)
@@ -27,7 +27,7 @@ class command(SimpleFormat):
return ' '.join(self.MERGED(protect_safe=True))
@SimpleFormat.producing(SEPARATED, protect=True)
- def get_separated(self, protocol):
+ def get_separated(self, *protodecl):
ret = self.MERGED(protect_safe=True)
newret, acc = [], []
for i in ret:
@@ -42,7 +42,7 @@ class command(SimpleFormat):
return newret
@SimpleFormat.producing(MERGED, protect=True)
- def get_merged(self, protocol):
+ def get_merged(self, *protodecl):
# try to look (indirectly) if we have "separated" at hand first
if self.BYTESTRING in self._representations: # break the possible loop
from shlex import split
diff --git a/formats/simpleconfig.py b/formats/simpleconfig.py
index 57408a1..04df34b 100644
--- a/formats/simpleconfig.py
+++ b/formats/simpleconfig.py
@@ -45,7 +45,7 @@ class simpleconfig(SimpleFormat):
BYTESTRING = SimpleFormat.BYTESTRING
@SimpleFormat.producing(BYTESTRING)
- def get_bytestring(self, protocol):
+ def get_bytestring(self, *protodecl):
"""Externalize 'struct', that is basically, pretty print it
For example above, the result is something like:
@@ -115,6 +115,6 @@ class simpleconfig(SimpleFormat):
return ret
@SimpleFormat.producing(STRUCT, protect=True)
- def get_struct(self, protocol):
+ def get_struct(self, *protodecl):
# TODO parsing struct from string
raise NotImplementedError