Construct a MultiplexedPath if needed. If children contains a sole element, return it. Otherwise, return a MultiplexedPath of the items. Unless one of the items is not a Directory, then return the first.
(cls, children)
| 105 | |
| 106 | @classmethod |
| 107 | def _follow(cls, children): |
| 108 | """ |
| 109 | Construct a MultiplexedPath if needed. |
| 110 | |
| 111 | If children contains a sole element, return it. |
| 112 | Otherwise, return a MultiplexedPath of the items. |
| 113 | Unless one of the items is not a Directory, then return the first. |
| 114 | """ |
| 115 | subdirs, one_dir, one_file = itertools.tee(children, 3) |
| 116 | |
| 117 | try: |
| 118 | return only(one_dir) |
| 119 | except ValueError: |
| 120 | try: |
| 121 | return cls(*subdirs) |
| 122 | except NotADirectoryError: |
| 123 | return next(one_file) |
| 124 | |
| 125 | def open(self, *args, **kwargs): |
| 126 | raise FileNotFoundError(f'{self} is not a file') |