|
11 | 11 | from types import TracebackType |
12 | 12 | from typing import (TYPE_CHECKING, AnyStr, BinaryIO, Generator, Iterable, |
13 | 13 | Iterator, Type, Union) |
| 14 | +from urllib import parse |
14 | 15 |
|
15 | 16 | from .._property import _cached_property |
16 | 17 | from ..errors import NotFound |
@@ -570,15 +571,19 @@ def exists(self, path: str) -> bool: |
570 | 571 | p = self._path(path) |
571 | 572 | return p.exists() |
572 | 573 |
|
| 574 | + __ALLOWED_SCHEMES = [None, 'file', 'dbfs'] |
| 575 | + |
573 | 576 | def _path(self, src): |
574 | | - src = str(src) |
575 | | - if src.startswith('file:'): |
576 | | - return _LocalPath(src) |
577 | | - if src.startswith('dbfs:'): |
578 | | - src = src[len('dbfs:'):] |
579 | | - if src.startswith('/Volumes'): |
580 | | - return _VolumesPath(self._files_api, src) |
581 | | - return _DbfsPath(self._dbfs_api, src) |
| 577 | + src = parse.urlparse(str(src)) |
| 578 | + if src.scheme and src.scheme not in self.__ALLOWED_SCHEMES: |
| 579 | + raise ValueError( |
| 580 | + f'unsupported scheme "{src.scheme}". DBUtils in the SDK only supports local, root DBFS, and ' |
| 581 | + 'UC Volumes paths, not external locations or DBFS mount points.') |
| 582 | + if src.scheme == 'file': |
| 583 | + return _LocalPath(src.geturl()) |
| 584 | + if src.path.startswith('/Volumes'): |
| 585 | + return _VolumesPath(self._files_api, src.geturl()) |
| 586 | + return _DbfsPath(self._dbfs_api, src.geturl()) |
582 | 587 |
|
583 | 588 | def copy(self, src: str, dst: str, *, recursive=False, overwrite=False): |
584 | 589 | """Copy files between DBFS and local filesystems""" |
|
0 commit comments