def parse_path(path): """Parse a dataset's identifier or path into its parts Parameters ---------- path : str or path-like object The path to be parsed. Returns ------- ParsedPath or UnparsedPath Notes ----- When legacy GDAL filenames are encountered, they will be returned in a UnparsedPath. """ # Windows drive letters (e.g. "C:\") confuse `urlparse` as they look like # URL schemes if sys.platform == "win32" and re.match("^[a-zA-Z]\\:", path): return UnparsedPath(path) elif path.startswith('/vsi'): return UnparsedPath(path) else: parts = urlparse(path) # if the scheme is not one of Rasterio's supported schemes, we # return an UnparsedPath. if parts.scheme and not all(p in SCHEMES for p in parts.scheme.split('+')): return UnparsedPath(path) else: return ParsedPath.from_uri(path)
def parse_path(path): """Parse a dataset's identifier or path into its parts Parameters ---------- path : str or path-like object The path to be parsed. Returns ------- ParsedPath or UnparsedPath Notes ----- When legacy GDAL filenames are encountered, they will be returned in a UnparsedPath. """ # Windows drive letters (e.g. "C:\") confuse `urlparse` as they look like # URL schemes if sys.platform == "win32" and re.match("^[a-zA-Z]\\:", path): return UnparsedPath(path) elif path.startswith('/vsi'): return UnparsedPath(path) else: parts = urlparse(path) # if the scheme is not one of Rasterio's supported schemes, we # return an UnparsedPath. if parts.scheme and not all(p in SCHEMES for p in parts.scheme.split('+')): return UnparsedPath(path) else: return ParsedPath.from_uri(path)
def parse_path(uri, vfs=None): """Parse a URI or Apache VFS URL into its parts Returns: tuple (path, archive, scheme) """ archive = scheme = None path = uri if vfs: parts = urlparse(vfs) scheme = parts.scheme archive = parts.path if parts.netloc and parts.netloc != 'localhost': # pragma: no cover archive = parts.netloc + archive else: parts = urlparse(path) scheme = parts.scheme path = parts.path if parts.query: path += "?" + parts.query if parts.netloc and parts.netloc != 'localhost': path = parts.netloc + path # There are certain URI schemes we favor over GDAL's names. if scheme in SCHEMES: parts = path.split('!') path = parts.pop() if parts else None archive = parts.pop() if parts else None # For filesystem paths. elif scheme.lower() in FILE_SCHEMES: pass # We permit GDAL's idiosyncratic URI-like dataset paths such as # 'netcdf':... to fall right through with no parsed archive # or scheme. else: archive = scheme = None path = uri return path, archive, scheme
def parse_path(uri, vfs=None): """Parse a URI or Apache VFS URL into its parts Returns: tuple (path, archive, scheme) """ archive = scheme = None path = uri if vfs: parts = urlparse(vfs) scheme = parts.scheme archive = parts.path if parts.netloc and parts.netloc != 'localhost': # pragma: no cover archive = parts.netloc + archive else: parts = urlparse(path) scheme = parts.scheme path = parts.path if parts.query: path += "?" + parts.query if parts.netloc and parts.netloc != 'localhost': path = parts.netloc + path # There are certain URI schemes we favor over GDAL's names. if scheme in SCHEMES: parts = path.split('!') path = parts.pop() if parts else None archive = parts.pop() if parts else None # For filesystem paths. elif scheme.lower() in FILE_SCHEMES: pass # We permit GDAL's idiosyncratic URI-like dataset paths such as # 'netcdf':... to fall right through with no parsed archive # or scheme. else: archive = scheme = None path = uri return path, archive, scheme
def parse_path(path): """Parse a dataset's identifier or path into its parts Parameters ---------- path : str or path-like object The path to be parsed. Returns ------- ParsedPath or UnparsedPath Notes ----- When legacy GDAL filenames are encountered, they will be returned in a UnparsedPath. """ if isinstance(path, Path): return path elif pathlib and isinstance(path, pathlib.PurePath): return ParsedPath(path.as_posix(), None, None) elif isinstance(path, string_types): if sys.platform == "win32" and re.match(r"^[a-zA-Z]\:", path): if pathlib: return ParsedPath(pathlib.Path(path).as_posix(), None, None) else: return UnparsedPath(path) elif path.startswith('/vsi'): return UnparsedPath(path) else: parts = urlparse(path) else: raise PathError("invalid path '{!r}'".format(path)) # if the scheme is not one of Rasterio's supported schemes, we # return an UnparsedPath. if parts.scheme: if all(p in SCHEMES for p in parts.scheme.split('+')): return ParsedPath.from_uri(path) return UnparsedPath(path)
def from_uri(cls, uri): parts = urlparse(uri) path = parts.path scheme = parts.scheme or None if parts.query: path += "?" + parts.query if parts.scheme and parts.netloc: path = parts.netloc + path parts = path.split('!') path = parts.pop() if parts else None archive = parts.pop() if parts else None return ParsedPath(path, archive, scheme)
def from_uri(cls, uri): parts = urlparse(uri) path = parts.path scheme = parts.scheme or None if parts.query: path += "?" + parts.query if parts.scheme and parts.netloc: path = parts.netloc + path parts = path.split('!') path = parts.pop() if parts else None archive = parts.pop() if parts else None return ParsedPath(path, archive, scheme)
def parse_path(path, vfs=None): """Parse a dataset's path into its parts **DEPRECATED** Parameters ---------- path : str The path or filename to be parsed. vfs : str, optional **DEPRECATED** A virtual file system path. Returns ------- path, archive, scheme : str Parts of the parsed path. """ warnings.warn( "This function will be removed in version 1.0", RasterioDeprecationWarning ) if vfs: parts = urlparse(vfs) scheme = parts.scheme archive = parts.path if parts.netloc and parts.netloc != 'localhost': # pragma: no cover archive = parts.netloc + archive parsed = ParsedPath(path, archive, scheme) return parsed.path, parsed.archive, parsed.scheme else: parsed = future_parse_path(path) if isinstance(parsed, ParsedPath): return parsed.path, parsed.archive, parsed.scheme else: return parsed.path, None, None