diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-24 07:31:51 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-24 07:31:51 -0500 |
commit | d248dbca39e1e8a26a5aa9d39b28038690a406a0 (patch) | |
tree | f730cd2e12e0d328b91b3636f2a30356c39c9da6 /libbe/utility.py | |
parent | 63a7726eba738fe2ed340027039ba655ff91898a (diff) | |
download | bugseverywhere-d248dbca39e1e8a26a5aa9d39b28038690a406a0.tar.gz |
Replaced direct filesystem read from bugdir.py with RCS mediated read.
Also replaced utility.FileString with StringIO() in cmdutil.py, which
allowed the removal of utility.FileString and utility.get_file.
The only remaining file().read() outside the RCS framework is the read
in utility.editor_string(), but should probably not go through the
RCS.
Diffstat (limited to 'libbe/utility.py')
-rw-r--r-- | libbe/utility.py | 51 |
1 files changed, 1 insertions, 50 deletions
diff --git a/libbe/utility.py b/libbe/utility.py index 7c1d10a..1168580 100644 --- a/libbe/utility.py +++ b/libbe/utility.py @@ -21,55 +21,6 @@ import tempfile import shutil import doctest -class FileString(object): - """Bare-bones pseudo-file class - - >>> f = FileString("me\\nyou") - >>> len(list(f)) - 2 - >>> len(list(f)) - 0 - >>> f = FileString() - >>> f.write("hello\\nthere") - >>> "".join(list(f)) - 'hello\\nthere' - """ - def __init__(self, str=""): - object.__init__(self) - self.str = str - self._iter = None - - def __iter__(self): - if self._iter is None: - self._iter = self._get_iter() - return self._iter - - def _get_iter(self): - for line in self.str.splitlines(True): - yield line - - def write(self, line): - self.str += line - - -def get_file(f): - """ - Return a file-like object from input. This is a helper for functions that - can take either file or string parameters. - - :param f: file or string - :return: a FileString if input is a string, otherwise return the imput - object. - - >>> isinstance(get_file(file("/dev/null")), file) - True - >>> isinstance(get_file("f"), FileString) - True - """ - if isinstance(f, basestring): - return FileString(f) - else: - return f def search_parent_directories(path, filename): """ @@ -175,7 +126,7 @@ def editor_string(comment=None): os.close(fhandle) oldmtime = os.path.getmtime(fname) os.system("%s %s" % (editor, fname)) - output = trimmed_string(file(fname, "rb").read()) + output = trimmed_string(file(fname, "rb").read().decode("utf-8")) if output.rstrip('\n') == "": output = None finally: |