URI API
Uri (pure URI paths), UriPath (URI paths with I/O and scheme dispatch),
Source and Query. The built-in schemes are documented under Schemes.
pathlib_next.uri
UriLike = 'str | Uri | os.PathLike'
module-attribute
Uri(*uris, **options)
Bases: Pathname
A pure (no I/O) RFC 3986 URI, lazily parsed into source (scheme/
userinfo/host/port), path, query, and fragment on first access.
Join semantics (multiple constructor args, or /) are pathlib-
joinpath-like, not RFC 3986 reference resolution -- see
_load_parts's docstring and docs/divergences.md.
Source code in src/pathlib_next/uri/__init__.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
fragment
property
normalized_path
property
Return the normalized path using posixpath rules.
parent
property
The logical parent of the path.
parts
property
The tuple of URI components: (source, path, query, fragment).
path
property
query
property
The query exactly as received: still percent-encoded, so an
escaped &, = or + inside a value survives the round trip. Use
Query.decode()/to_dict() for decoded pairs.
segments
property
source
property
stem
property
suffix
property
as_posix()
Source code in src/pathlib_next/uri/__init__.py
816 817 818 819 820 821 822 823 824 825 826 827 | |
as_uri(sanitize=False)
Source code in src/pathlib_next/uri/__init__.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
host_fspath()
Return .path for any scheme whose path component is a
filesystem path on the URI's own host (see _host_filesystem_path),
for building a command line that runs on that host (e.g. via a
remote executor). Unlike __fspath__, this never falls back to
treating the path as local -- it raises NotImplementedError for
schemes with no host-filesystem meaning (http:, s3:, ...).
Source code in src/pathlib_next/uri/__init__.py
529 530 531 532 533 534 535 536 537 538 | |
is_absolute()
True if the path is absolute: it starts with "/", with or without
a source (as PurePosixPath("/a") is absolute).
Source code in src/pathlib_next/uri/__init__.py
705 706 707 708 | |
is_local()
Return True if the URI points to a local resource.
Source code in src/pathlib_next/uri/__init__.py
765 766 767 | |
is_relative_to(other)
Return True if the path is relative to another path or False.
Source code in src/pathlib_next/uri/__init__.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
joinpath(*args)
Combine this URI with segments; a str is a decoded path.
Source code in src/pathlib_next/uri/__init__.py
796 797 798 799 800 801 802 803 804 805 806 | |
relative_to(other, *, walk_up=False)
Source code in src/pathlib_next/uri/__init__.py
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | |
with_fragment(fragment)
Return a new URI with the fragment replaced.
Source code in src/pathlib_next/uri/__init__.py
640 641 642 | |
with_path(path)
Return a new URI with the path replaced.
Source code in src/pathlib_next/uri/__init__.py
621 622 623 624 625 626 627 628 | |
with_query(query)
Return a new URI with the query replaced.
A str is taken in the percent-encoded form .query returns and is
sent as given; a mapping or a sequence of pairs is encoded by
Query.
Source code in src/pathlib_next/uri/__init__.py
630 631 632 633 634 635 636 637 638 | |
with_segments(*segments)
Return a new URI with the path segments replaced.
Source code in src/pathlib_next/uri/__init__.py
615 616 617 618 619 | |
with_source(source)
Return a new URI with the source replaced.
Source code in src/pathlib_next/uri/__init__.py
611 612 613 | |
UriPath(*uris, **options)
Uri + Path (I/O) + scheme dispatch. UriPath(...) constructs
the concrete subclass registered for the URI's scheme (via __SCHEMES)
-- e.g. UriPath("http://...") returns an HttpPath. Subclass this
and set __SCHEMES to add a new scheme (Track B of extending this
library; see docs/guides/extending.md); implement the I/O surface
(_listdir or _scandir, stat, _open, ...) documented in
docs/guides/extending.md. Prefer overriding _scandir() over _listdir() when the
listing call already returns type/size/mtime metadata (PROPFIND, MLSD,
listdir_attr, an S3 list page, ...) -- walk()/glob() then answer
is_dir() on the results for free, without a stat request per entry.
Source code in src/pathlib_next/uri/__init__.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
backend
property
The connection or session state backend instance.
iterdir()
Source code in src/pathlib_next/uri/__init__.py
1216 1217 1218 | |
joinpath(*args)
Combine this path with segments, choosing the result's class from
its scheme as / does: joining an absolute local path gives a
FileUri, not this class carrying a file: URI.
Each str argument is an already-decoded path (see
Uri._join_arg); pass a Uri for a scheme-aware join.
Source code in src/pathlib_next/uri/__init__.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 | |
with_backend(backend)
Return a new path instance sharing the same backend state.
Source code in src/pathlib_next/uri/__init__.py
1104 1105 1106 | |
with_source(source)
Source code in src/pathlib_next/uri/__init__.py
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
pathlib_next.uri.source
Source
Bases: NamedTuple
A URI's scheme/userinfo/host/port -- everything before the path.
Falsy (bool(source) is False) when every field is empty/None.
host
instance-attribute
port
instance-attribute
scheme
instance-attribute
userinfo
instance-attribute
as_str(sanitize=True)
Compose this Source back into an authority string
(scheme://userinfo@host:port). sanitize=True (the default,
matching __str__) drops the password from userinfo; pass
sanitize=False for the full, credentialed round trip -- the
same escape hatch Uri.as_uri(sanitize=False) provides one layer
up. Mirrors Uri.as_uri()'s name/kwarg exactly so both classes
are used the same way.
Source code in src/pathlib_next/uri/source.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
from_str(source, strict=True)
classmethod
Source code in src/pathlib_next/uri/source.py
310 311 312 313 314 315 316 317 318 319 320 321 | |
get_scheme_cls(schemesmap=None)
The UriPath subclass registered for this scheme, or UriPath
itself. An explicit schemesmap is the complete set of classes to
choose from: a scheme missing from it gives UriPath, and neither
plugins nor the global registry are consulted.
Source code in src/pathlib_next/uri/source.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
is_local()
cached
Whether host resolves to this machine.
Caches per unique Source (Source is an immutable value type), since this does a DNS/hosts-file lookup -- never call it on a hot path uncached.
The hostname->address step uses netimps.resolve() (default
backend chain: dnspython, then the OS resolver via
getaddrinfo() -- hosts file, NSS, DNS, OS cache -- then
nslookup as a last resort), trying both "a"/"aaaa" record
types and treating host as local if ANY resolved address is.
netimps.resolve() gained OS-resolver-chain support in 0.2.0 --
before that it was dnspython-only, which is why this method
originally kept socket.gethostbyname() for this step. The
"is this address MINE" comparison uses netimps.is_local_address(),
which enumerates real network interfaces
(netimps.get_interfaces()) instead of the weaker
socket.getaddrinfo(socket.gethostname(), None) this project used
originally -- that approach missed addresses not tied to the
resolvable hostname (VMs, containers, VPN interfaces, additional
NICs on a multi-homed host).
host as a bare IP-literal str (e.g. a directly-constructed
Source(..., host="::1", ...), bypassing _decode_host()'s usual
bracket-literal parsing) is handled by netimps.try_parse()
without going through resolution at all.
Source code in src/pathlib_next/uri/source.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
keys()
Source code in src/pathlib_next/uri/source.py
323 324 | |
parsed_userinfo()
Source code in src/pathlib_next/uri/source.py
331 332 333 334 335 336 | |
pathlib_next.uri.query
Query
Bases: str
A URI query string (str subclass) that can also be built from a
dict/list of pairs and decoded back with to_dict()/iteration.
The string is always the percent-encoded form: a str argument is
taken as already encoded (it is what Uri.query holds, as received),
a mapping or pair sequence is encoded here, and decode()/to_dict()
decode each name and value exactly once.
ENCODING = 'utf-8'
class-attribute
instance-attribute
SEPARATOR = '&'
class-attribute
instance-attribute
decode(query)
Source code in src/pathlib_next/uri/query.py
94 95 96 97 | |
to_dict(query, *, single=False)
Source code in src/pathlib_next/uri/query.py
102 103 104 105 106 107 108 109 | |