|
1 | 1 | from __future__ import absolute_import |
2 | 2 |
|
3 | 3 | import abc |
4 | | -import itertools |
5 | 4 |
|
6 | | -from ._compat import ABC, FileNotFoundError, suppress |
| 5 | +from ._compat import ABC, FileNotFoundError |
7 | 6 |
|
8 | 7 | # Use mypy's comment syntax for Python 2 compatibility |
9 | 8 | try: |
@@ -117,54 +116,6 @@ def open(self, mode='r', *args, **kwargs): |
117 | 116 | """ |
118 | 117 |
|
119 | 118 |
|
120 | | -class Multiplexed(Traversable): |
121 | | - """ |
122 | | - Given a series of Traversable objects, implement a merged |
123 | | - version of the interface across all objects. Useful for |
124 | | - namespace packages which may be multihomed at a single |
125 | | - name. |
126 | | - """ |
127 | | - |
128 | | - def __init__(self, *paths): |
129 | | - self._paths = paths |
130 | | - |
131 | | - def iterdir(self): |
132 | | - return itertools.chain.from_iterable( |
133 | | - path.iterdir() for path in self._paths) |
134 | | - |
135 | | - def read_bytes(self): |
136 | | - return self.open(mode='rb').read() |
137 | | - |
138 | | - def read_text(self, *args, **kwargs): |
139 | | - return self.open(mode='r', *args, **kwargs).read() |
140 | | - |
141 | | - def is_dir(self): |
142 | | - return any(path.is_dir() for path in self._paths) |
143 | | - |
144 | | - def is_file(self): |
145 | | - return any(path.is_file() for path in self._paths) |
146 | | - |
147 | | - def joinpath(self, child): |
148 | | - children = ( |
149 | | - path.joinpath(child) |
150 | | - for path in self._paths |
151 | | - ) |
152 | | - existing = ( |
153 | | - child |
154 | | - for child in children |
155 | | - if child.is_dir() or child.is_file() |
156 | | - ) |
157 | | - return Multiplexed(*existing) |
158 | | - |
159 | | - __truediv__ = joinpath |
160 | | - |
161 | | - def open(self, *args, **kwargs): |
162 | | - for path in self._paths[:-1]: |
163 | | - with suppress(Exception): |
164 | | - return path.open(*args, **kwargs) |
165 | | - return self._paths[-1].open(*args, **kwargs) |
166 | | - |
167 | | - |
168 | 119 | class TraversableResources(ResourceReader): |
169 | 120 | @abc.abstractmethod |
170 | 121 | def files(self): |
|
0 commit comments