diff options
author | W. Trevor King <wking@drexel.edu> | 2009-06-26 09:27:50 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-06-26 09:27:50 -0400 |
commit | 97aeb18b20f901950da0355471fdc17055f3f4a8 (patch) | |
tree | 83caecf530df36cc9f88bd94373b0fea0129b979 /libbe/rcs.py | |
parent | 033a4446c1522c9ff288afa6bc47c3d15d290216 (diff) | |
download | bugseverywhere-97aeb18b20f901950da0355471fdc17055f3f4a8.tar.gz |
Added ability to handle non text/* MIME types.
The main problem was the encoding/decoding that was happening to _all_
input/output. Now many I/O activities have a `binary' option to
disable any encoding/decoding. The `binary' flag is set whenever the
comment content-type is not a text/* type.
In order to print valid XML (and make life easy on xml/be-xml-to-mbox),
non text/* types are printed out as base64-encoded MIME messages, so
be list --xml | be-xml-to-mbox | catmutt
works as you'd expect.
With the standard (non-XML) output from `be show', we just print a
message telling the user that we can't reasonably display the MIME
type and that they should use the XML output if they want to see it.
Diffstat (limited to 'libbe/rcs.py')
-rw-r--r-- | libbe/rcs.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libbe/rcs.py b/libbe/rcs.py index 3428ce0..9c2defe 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -172,14 +172,17 @@ class RCS(object): at path. """ pass - def _rcs_get_file_contents(self, path, revision=None): + def _rcs_get_file_contents(self, path, revision=None, binary=False): """ Get the file contents as they were in a given revision. Revision==None specifies the current revision. """ assert revision == None, \ "The %s RCS does not support revision specifiers" % self.name - f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding) + if binary == False: + f = codecs.open(os.path.join(self.rootdir, path), "r", self.encoding) + else: + f = open(path, "rb") contents = f.read() f.close() return contents @@ -290,7 +293,7 @@ class RCS(object): at path. """ self._rcs_update(self._u_rel_path(path)) - def get_file_contents(self, path, revision=None, allow_no_rcs=False): + def get_file_contents(self, path, revision=None, allow_no_rcs=False, binary=False): """ Get the file as it was in a given revision. Revision==None specifies the current revision. @@ -299,18 +302,21 @@ class RCS(object): raise NoSuchFile(path) if self._use_rcs(path, allow_no_rcs): relpath = self._u_rel_path(path) - contents = self._rcs_get_file_contents(relpath,revision) + contents = self._rcs_get_file_contents(relpath,revision,binary=binary) else: f = codecs.open(path, "r", self.encoding) contents = f.read() f.close() return contents - def set_file_contents(self, path, contents, allow_no_rcs=False): + def set_file_contents(self, path, contents, allow_no_rcs=False, binary=False): """ Set the file contents under version control. """ add = not os.path.exists(path) - f = codecs.open(path, "w", self.encoding) + if binary == False: + f = codecs.open(path, "w", self.encoding) + else: + f = open(path, "wb") f.write(contents) f.close() |