Bases: URIPath
data: scheme (RFC 2397): a read-only "file" whose entire content is
embedded in the URI itself (data:[<mediatype>][;base64],<data>) -- no
filesystem, no directories, no backend/connection. RFC 2397 has no query,
so an unescaped ? and what follows it are payload; a # starts the
fragment, as in any URI, and is not.
Source code in src/uripath/_uri.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 | def __init__(self, *uris: URILike, **options):
if options:
self._check_options(options)
if self._raw_uris or self._initiated:
return
_uris: list[str | URI] = []
for uri in uris:
if uri is None or (isinstance(uri, (str, bytes)) and not uri):
uri = ""
if isinstance(uri, URI):
_uris.append(uri)
elif isinstance(uri, (_pathlib.Path, Path)):
try:
uri = uri.as_uri()
except ValueError:
# as_uri() raises ValueError for a relative path, which
# joins like a relative PurePath (see _RelativeLocalPath).
uri = _RelativeLocalPath(_uriencode(uri.as_posix(), safe="/"))
_uris.append(uri)
elif isinstance(uri, (_pathlib.PurePath, Pathname)):
_uris.append(_path_reference(uri.as_posix()))
elif hasattr(uri, "as_uri"):
path = uri.as_uri
if callable(path):
path = path()
_uris.append(path)
elif isinstance(uri, str):
_uris.append(uri)
elif isinstance(uri, bytes):
_uris.append(uri.decode())
else:
path = None
try:
path = os.fspath(uri)
except (TypeError, NotImplementedError):
pass
if not isinstance(path, str):
raise TypeError(
"argument should be a str or an os.PathLike "
"object where __fspath__ returns a str, "
f"not {type(uri).__name__!r}"
)
# Only __fspath__ is guaranteed here -- posix-normalize the
# string itself rather than assuming an as_posix() method.
posix = _pathlib.PurePath(path).as_posix()
_uris.append(_path_reference(posix))
self._raw_uris = _uris
|
charset
property
The charset the media type declares (charset=utf-8, quotes
removed), or "utf-8" when it declares none: a text payload is read
in it by open() and read_text() unless encoding= says
otherwise. UTF-8 reads what the RFC's US-ASCII default names, and more.
The declared media type. Without a type/subtype, RFC 2397 implies
"text/plain": a bare header gives "text/plain;charset=US-ASCII",
and parameters alone (";charset=utf-8") are given that type.
open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)
Source code in src/uripath/schemes/_data.py
| def open(self, mode="r", buffering=-1, encoding=None, errors=None, newline=None):
if encoding is None and "b" not in mode:
encoding = self.charset
return super().open(mode, buffering, encoding, errors, newline)
|
stat(*, follow_symlinks=True)
Source code in src/uripath/schemes/_data.py
| def stat(self, *, follow_symlinks=True):
return FileStat(st_size=len(self._content()), is_dir=False)
|