Memory Path API
pathapi.mempath
MemBytesIO(dest, *, append=False)
Bases: BytesIO
A BytesIO that writes its buffer back into the backing
bytearray (dest) on flush() and close, so MemPath files persist
across open() calls. With append=True every write lands at the end,
like O_APPEND, whatever the current position, and only the bytes this
handle wrote are added to dest, so two appenders both land.
Source code in src/pathapi/mempath.py
65 66 67 68 69 70 71 72 73 | |
close()
Source code in src/pathapi/mempath.py
106 107 108 109 | |
flush()
Source code in src/pathapi/mempath.py
101 102 103 104 | |
write(data)
Source code in src/pathapi/mempath.py
91 92 93 94 | |
writelines(lines)
Source code in src/pathapi/mempath.py
96 97 98 99 | |
MemFile(*args)
Bases: bytearray
A file's content in a MemPathBackend, carrying its modification
time. A plain bytearray placed in a backend by hand still works; it
reports st_mtime 0.
Source code in src/pathapi/mempath.py
31 32 33 34 | |
mtime = 0.0
instance-attribute
MemPath(*segments, backend=None)
Bases: Path
In-memory Path implementation over nested dicts (see
MemPathBackend) -- a lightweight virtual filesystem for mocks, tests,
or transient storage, and the reference exemplar for Track A of
extending this library (subclassing Path directly; see
docs/guides/extending.md).
Source code in src/pathapi/mempath.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
backend
property
normalized
property
The names of this path with .. applied to the text and clamped
at the root; [""] for the root. _node_key() reads it.
parent
property
parts
property
segments
property
as_uri()
Source code in src/pathapi/mempath.py
284 285 | |
iterdir()
Source code in src/pathapi/mempath.py
392 393 394 395 396 397 398 399 400 | |
relative_to(other, *, walk_up=False)
self below other, as a relative path on the same backend.
other is a MemPath of the same backend or a str. Names are
compared as written, with no .. applied. ValueError when self
is not below other, when the two differ in being rooted, or when
the backends differ. With walk_up, a path beside other gets a
.. per level climbed; a .. in other cannot be walked.
Source code in src/pathapi/mempath.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
rmdir()
Source code in src/pathapi/mempath.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
stat(*, follow_symlinks=True)
Source code in src/pathapi/mempath.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
unlink(missing_ok=False)
Source code in src/pathapi/mempath.py
347 348 349 350 351 352 353 354 355 356 357 358 359 | |
with_segments(*segments)
Source code in src/pathapi/mempath.py
277 278 279 280 281 282 | |
MemPathBackend
Bases: dict
Nested-dict storage backing one or more MemPath trees. A dict
value is a directory; a bytearray value is a file's content. Share
one instance across MemPaths (via backend=) to give them the same
virtual filesystem.