diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-08-02 01:32:37 -0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-08-02 01:32:37 -0300 |
commit | 7ab1514eb4cf21f57e2dc638acdfab82bbdd472e (patch) | |
tree | d3011be54eaa9ff7fac9c82402a1186946fbd674 /gbp/git | |
parent | 9cdac4a84ee4a9f24c162ff8d9f6b89b1fb7099d (diff) |
Make GitVFS support binary mode
this makes it work with Python3 too
Diffstat (limited to 'gbp/git')
-rw-r--r-- | gbp/git/vfs.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/gbp/git/vfs.py b/gbp/git/vfs.py index 4ca29625..8363f77b 100644 --- a/gbp/git/vfs.py +++ b/gbp/git/vfs.py @@ -16,7 +16,7 @@ # <http://www.gnu.org/licenses/> """Make blobs in a git repository accessible as file like objects""" -from six import StringIO +import io from gbp.git.repository import GitRepositoryError @@ -28,9 +28,12 @@ class GitVfs(object): @todo: We don't support any byte ranges yet. """ - def __init__(self, content): + def __init__(self, content, binary=False): self._iter = iter - self._data = StringIO(content) + if binary: + self._data = io.BytesIO(content) + else: + self._data = io.StringIO(content.decode()) def readline(self): return self._data.readline() @@ -61,10 +64,12 @@ class GitVfs(object): def open(self, path, flags=None): flags = flags or 'r' - if flags != 'r': - raise NotImplementedError("Only reading supported so far") + for flag in flags: + if flag not in ['r', 't', 'b']: + raise NotImplementedError("Flag '%s' unsupported so far" % flag) try: return GitVfs._File(self._repo.show( - "%s:%s" % (self._committish, path))) + "%s:%s" % (self._committish, path)), + True if 'b' in flags else False) except GitRepositoryError as e: - raise IOError(e) + raise OSError(e) |