diff --git a/dvc/remote/hdfs.py b/dvc/remote/hdfs.py index ec37ace63..efdbfbba4 100644 --- a/dvc/remote/hdfs.py +++ b/dvc/remote/hdfs.py @@ -143,6 +143,8 @@ class RemoteHDFS(RemoteBASE): @contextmanager def open(self, path_info, mode="r", encoding=None): + assert mode in {"r", "rt", "rb"} + try: with self.hdfs(path_info) as hdfs, closing( hdfs.open(path_info.path, mode="rb") diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index af9d7a92f..2f743a6ff 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -440,8 +440,6 @@ class Repo(object): @contextmanager def open(self, path, remote=None, mode="r", encoding=None): """Opens a specified resource as a file descriptor""" - assert mode in {"r", "rt", "rb"} - try: with self._open(path, remote, mode, encoding) as fd: yield fd diff --git a/dvc/utils/http.py b/dvc/utils/http.py index 7d8c6f55a..b2ecf4bb3 100644 --- a/dvc/utils/http.py +++ b/dvc/utils/http.py @@ -13,6 +13,8 @@ def open_url(url, mode="r", encoding=None): Resumes on connection error. Url could be a string or a callable returning a string. """ + assert mode in {"r", "rt", "rb"} + with iter_url(url) as (response, it): bytes_stream = IterStream(it)