|
15 | 15 |
|
16 | 16 | (defprotocol Coercions
|
17 | 17 | (as-path [f]
|
18 |
| - "Coerce ``f`` to a ``pathlib.Path`` instance. |
| 18 | + "Coerce ``f`` to a :external:py:class:`pathlib.Path` instance. |
19 | 19 |
|
20 | 20 | Callers should generally prefer :lpy:fn:`basilisp.io/path` to this function."))
|
21 | 21 |
|
|
42 | 42 | {:file f})))))
|
43 | 43 |
|
44 | 44 | (defn path
|
45 |
| - "Coerce ``p`` to a ``pathlib.Path`` instance. |
| 45 | + "Coerce ``p`` to a :external:py:class:`pathlib.Path` instance. |
46 | 46 |
|
47 | 47 | When multiple arguments are provided, treat the first as the parent path and
|
48 | 48 | each subsequent argument as a child path, joining all paths together as one."
|
|
293 | 293 | "Open a reader instance on the file or path ``f``.
|
294 | 294 |
|
295 | 295 | The reader instances returned are always text-based, not binary. In general, the
|
296 |
| - readers should be compatible with Python's ``io.TextIOBase`` interface. |
| 296 | + readers should be compatible with Python's :external:py:class:`io.TextIOBase` |
| 297 | + interface. |
297 | 298 |
|
298 | 299 | Callers should take care to open a reader instance using
|
299 | 300 | :lpy:fn:`basilisp.core/with-open` to ensure that any resources are properly closed
|
300 |
| - afterwards. Note that for in-memory IO buffers such as ``io.BytesIO`` and |
301 |
| - ``io.StringIO``, opening a reader without assigning it to a name for the duration of |
302 |
| - its use may trigger garbage collection of the reader which closes the underlying |
303 |
| - buffer, discarding the contents and invalidating the buffer. |
| 301 | + afterwards. Note that for in-memory IO buffers such as :external:py:class:`io.BytesIO` |
| 302 | + and :external:py:class:`io.StringIO`, opening a reader without assigning it to a name |
| 303 | + for the duration of its use may trigger garbage collection of the reader which closes |
| 304 | + the underlying buffer, discarding the contents and invalidating the buffer. |
304 | 305 |
|
305 | 306 | Default implementations are available for:
|
306 | 307 |
|
307 |
| - - ``io/TextIOBase`` (only if ``(.readable f)`` is ``true``) |
308 |
| - - ``io/RawIOBase`` |
309 |
| - - ``io/BufferedIOBase`` |
310 |
| - - ``python/str`` (first resolved as a URL via ``urllib.parse.urlparse``, then as a |
311 |
| - local filesystem path via ``pathlib``) |
312 |
| - - ``python/bytes`` |
313 |
| - - ``pathlib/Path`` |
314 |
| - - ``urllib.parse.ParseResult`` |
315 |
| - - ``urllib.request/Request``" |
| 308 | + - :external:py:class:`io.TextIOBase` (only if ``(.readable f)`` is ``true``) |
| 309 | + - :external:py:class:`io.RawIOBase` |
| 310 | + - :external:py:class:`io.BufferedIOBase` |
| 311 | + - :external:py:class:`str` (first resolved as a URL via |
| 312 | + :external:py:func:`urllib.parse.urlparse`, then as a local filesystem path via |
| 313 | + :external:py:mod:`pathlib`) |
| 314 | + - :external:py:class:`bytes` |
| 315 | + - :external:py:class:`pathlib.Path` |
| 316 | + - :external:py:class:`urllib.parse.ParseResult` |
| 317 | + - :external:py:class:`urllib.request.Request`" |
316 | 318 | [f & opts]
|
317 | 319 | (->> (apply hash-map opts)
|
318 | 320 | (clean-reader-mode)
|
|
322 | 324 | "Open a writer instance on the file or path ``f``.
|
323 | 325 |
|
324 | 326 | The writer instances returned are always text-based, not binary. In general, the
|
325 |
| - writers should be compatible with Python's ``io.TextIOBase`` interface. |
| 327 | + writers should be compatible with Python's :external:py:class:`io.TextIOBase` |
| 328 | + interface. |
326 | 329 |
|
327 | 330 | ``opts`` is an optional collection of keyword/value pairs
|
328 | 331 | transmitted as a map to the writer. The acceptable keywords align
|
329 |
| - with those recognized by the fn:``open`` function. Moreover, setting the |
| 332 | + with those recognized by the :lpy:fn:`open` function. Moreover, setting the |
330 | 333 | :append option to true will configure the writer for append mode.
|
331 | 334 |
|
332 | 335 | Callers should take care to open a writer instance using
|
333 | 336 | :lpy:fn:`basilisp.core/with-open` to ensure that any resources are properly closed
|
334 |
| - afterwards. Note that for in-memory IO buffers such as ``io.BytesIO`` and |
335 |
| - ``io.StringIO``, opening a writer without assigning it to a name for the duration of |
336 |
| - its use may trigger garbage collection of the writer which closes the underlying |
337 |
| - buffer, discarding the contents and invalidating the buffer. |
| 337 | + afterwards. Note that for in-memory IO buffers such as :external:py:class:`io.BytesIO` |
| 338 | + and :external:py:class:`io.StringIO`, opening a writer without assigning it to a name |
| 339 | + for the duration of its use may trigger garbage collection of the writer which closes |
| 340 | + the underlying buffer, discarding the contents and invalidating the buffer. |
338 | 341 |
|
339 | 342 | Default implementations are available for:
|
340 | 343 |
|
341 |
| - - ``io/TextIOBase`` (only if ``(.writable f)`` is ``true``) |
342 |
| - - ``io/RawIOBase`` |
343 |
| - - ``io/BufferedIOBase`` |
344 |
| - - ``python/str`` (first resolved as a URL via ``urllib.parse.urlparse``, then as a |
345 |
| - local filesystem path via ``pathlib``) |
346 |
| - - ``pathlib/Path`` |
347 |
| - - ``urllib.parse.ParseResult``" |
| 344 | + - :external:py:class:`io.TextIOBase` (only if ``(.writable f)`` is ``true``) |
| 345 | + - :external:py:class:`io.RawIOBase` |
| 346 | + - :external:py:class:`io.BufferedIOBase` |
| 347 | + - :external:py:class:`str` (first resolved as a URL via |
| 348 | + :external:py:func:`urllib.parse.urlparse`, then as a local filesystem path via |
| 349 | + :external:py:mod:`pathlib`) |
| 350 | + - :external:py:class:`pathlib.Path` |
| 351 | + - :external:py:class:`urllib.parse.ParseResult`" |
348 | 352 | [f & opts]
|
349 | 353 | (->> (apply hash-map opts)
|
350 | 354 | (clean-writer-mode)
|
|
354 | 358 | "Open an input stream instance on the file or path ``f``.
|
355 | 359 |
|
356 | 360 | The input stream instances returned are always binary, not text-based. In general,
|
357 |
| - the input streams should be compatible with Python's ``io.BufferedIOBase`` interface. |
| 361 | + the input streams should be compatible with Python's :external:py:class:`io.BufferedIOBase` interface. |
358 | 362 |
|
359 | 363 | Callers should take care to open a reader instance using
|
360 | 364 | :lpy:fn`basilisp.core/with-open` to ensure that any resources are properly closed
|
361 |
| - afterwards. Note that for in-memory IO buffers such as ``io.BytesIO`` and |
362 |
| - ``io.StringIO``, opening an input stream without assigning it to a name for the |
| 365 | + afterwards. Note that for in-memory IO buffers such as :external:py:class:`io.BytesIO` and |
| 366 | + :external:py:class:`io.StringIO`, opening an input stream without assigning it to a name for the |
363 | 367 | duration of its use may trigger garbage collection of the input stream which closes
|
364 | 368 | the underlying buffer, discarding the contents and invalidating the buffer.
|
365 | 369 |
|
366 | 370 | Default implementations are available for:
|
367 | 371 |
|
368 |
| - - ``io/RawIOBase`` |
369 |
| - - ``io/BufferedIOBase`` |
370 |
| - - ``python/str`` (first resolved as a URL via ``urllib.parse.urlparse``, then as a |
371 |
| - local filesystem path via ``pathlib``) |
372 |
| - - ``python/bytes`` |
373 |
| - - ``pathlib/Path`` |
374 |
| - - ``urllib.parse.ParseResult`` |
375 |
| - - ``urllib.request/Request``" |
| 372 | + - :external:py:class:`io.RawIOBase` |
| 373 | + - :external:py:class:`io.BufferedIOBase` |
| 374 | + - :external:py:class:`str` (first resolved as a URL via |
| 375 | + :external:py:func:`urllib.parse.urlparse`, then as a local filesystem path via |
| 376 | + :external:py:mod:`pathlib`) |
| 377 | + - :external:py:class:`bytes` |
| 378 | + - :external:py:class:`pathlib.Path` |
| 379 | + - :external:py:class:`urllib.parse.ParseResult` |
| 380 | + - :external:py:class:`urllib.request.Request`" |
376 | 381 | [f & opts]
|
377 | 382 | (->> (apply hash-map opts)
|
378 | 383 | (clean-reader-mode)
|
|
383 | 388 | "Open an output stream instance on the file or path ``f``.
|
384 | 389 |
|
385 | 390 | The output stream instances returned are always binary, not text-based. In general,
|
386 |
| - the output streams should be compatible with Python's ``io.BufferedIOBase`` interface. |
| 391 | + the output streams should be compatible with Python's :external:py:class:`io.BufferedIOBase` interface. |
387 | 392 |
|
388 | 393 | Callers should take care to open a writer instance using
|
389 | 394 | :lpy:fn:`basilisp.core/with-open` to ensure that any resources are properly closed
|
390 |
| - afterwards. Note that for in-memory IO buffers such as ``io.BytesIO`` and |
391 |
| - ``io.StringIO``, opening an output stream without assigning it to a name for the |
| 395 | + afterwards. Note that for in-memory IO buffers such as :external:py:class:`io.BytesIO` and |
| 396 | + :external:py:class:`io.StringIO`, opening an output stream without assigning it to a name for the |
392 | 397 | duration of its use may trigger garbage collection of the output stream which closes
|
393 | 398 | the underlying buffer, discarding the contents and invalidating the buffer.
|
394 | 399 |
|
395 | 400 | Default implementations are available for:
|
396 | 401 |
|
397 |
| - - ``io/RawIOBase`` |
398 |
| - - ``io/BufferedIOBase`` |
399 |
| - - ``python/str`` (first resolved as a URL via ``urllib.parse.urlparse``, then as a |
400 |
| - local filesystem path via ``pathlib``) |
401 |
| - - ``pathlib/Path`` |
402 |
| - - ``urllib.parse.ParseResult``" |
| 402 | + - :external:py:class:`io.RawIOBase` |
| 403 | + - :external:py:class:`io.BufferedIOBase` |
| 404 | + - :external:py:class:`str` (first resolved as a URL via |
| 405 | + :external:py:func:`urllib.parse.urlparse`, then as a local filesystem path via |
| 406 | + :external:py:mod:`pathlib`) |
| 407 | + - :external:py:class:`pathlib.Path` |
| 408 | + - :external:py:class:`urllib.parse.ParseResult`" |
403 | 409 | [f & opts]
|
404 | 410 | (->> (apply hash-map opts)
|
405 | 411 | (clean-writer-mode)
|
|
482 | 488 |
|
483 | 489 | ``input`` may be one of:
|
484 | 490 |
|
485 |
| - - ``io/TextIOBase`` |
486 |
| - - ``io/BufferedIOBase`` |
487 |
| - - ``pathlib/Path`` |
488 |
| - - ``python/bytes`` |
489 |
| - - ``python/str`` (assumed to be the contents to copy; not treated as a file path) |
| 491 | + - :external:py:class:`io.TextIOBase` |
| 492 | + - :external:py:class:`io.BufferedIOBase` |
| 493 | + - :external:py:class:`pathlib.Path` |
| 494 | + - :external:py:class:`bytes` |
| 495 | + - :external:py:class:`str` (assumed to be the contents to copy; not treated as a file path) |
490 | 496 |
|
491 | 497 | ``output`` may be one of:
|
492 | 498 |
|
493 |
| - - ``io/TextIOBase`` |
494 |
| - - ``io/BufferedIOBase`` |
495 |
| - - ``pathlib/Path`` |
| 499 | + - :external:py:class:`io.TextIOBase` |
| 500 | + - :external:py:class:`io.BufferedIOBase` |
| 501 | + - :external:py:class:`pathlib.Path` |
496 | 502 |
|
497 | 503 | Options include:
|
498 | 504 |
|
499 | 505 | :keyword ``:encoding``: used only when converting from binary to text buffers
|
500 | 506 | :keyword ``:buffer-size``: the buffer size of chunks when copying files manually
|
501 | 507 |
|
502 |
| - The default implementation where both arguments are ``pathlib/Path`` objects defer to |
503 |
| - Python's ``shutil/copyfile`` which provides default fast-path platform-specific |
| 508 | + The default implementation where both arguments are :external:py:class:`pathlib.Path` objects defer to |
| 509 | + Python's :external:py:func:`shutil.copyfile` which provides default fast-path platform-specific |
504 | 510 | implementations wherever available in Python 3.8+.
|
505 | 511 |
|
506 | 512 | Additional implementations may be added by providing additional methods (via
|
|
0 commit comments