fastcore 2.2.32__tar.gz → 2.2.34__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {fastcore-2.2.32/fastcore.egg-info → fastcore-2.2.34}/PKG-INFO +14 -16
  2. {fastcore-2.2.32 → fastcore-2.2.34}/README.md +13 -15
  3. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/__init__.py +14 -14
  4. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/_modidx.py +1 -0
  5. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/ansi.py +5 -4
  6. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/basics.py +5 -4
  7. fastcore-2.2.34/fastcore/editskill.py +62 -0
  8. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/funccall.py +6 -12
  9. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/nbio.py +10 -7
  10. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/net.py +24 -14
  11. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/style.py +1 -1
  12. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/test.py +1 -1
  13. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/xdg.py +1 -1
  14. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/xml.py +1 -0
  15. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/xtras.py +1 -1
  16. {fastcore-2.2.32 → fastcore-2.2.34/fastcore.egg-info}/PKG-INFO +14 -16
  17. fastcore-2.2.32/fastcore/editskill.py +0 -64
  18. {fastcore-2.2.32 → fastcore-2.2.34}/CONTRIBUTING.md +0 -0
  19. {fastcore-2.2.32 → fastcore-2.2.34}/LICENSE +0 -0
  20. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/aio.py +0 -0
  21. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/all.py +0 -0
  22. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/apisurface.py +0 -0
  23. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/dispatch.py +0 -0
  24. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/docments.py +0 -0
  25. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/docscrape.py +0 -0
  26. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/foundation.py +0 -0
  27. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/imghdr.py +0 -0
  28. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/imports.py +0 -0
  29. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/meta.py +0 -0
  30. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/nb_imports.py +0 -0
  31. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/parallel.py +0 -0
  32. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/py2pyi.py +0 -0
  33. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/script.py +0 -0
  34. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/shutil.py +0 -0
  35. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/tools.py +0 -0
  36. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/transform.py +0 -0
  37. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore/utils.py +0 -0
  38. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore.egg-info/SOURCES.txt +0 -0
  39. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore.egg-info/dependency_links.txt +0 -0
  40. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore.egg-info/entry_points.txt +0 -0
  41. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore.egg-info/requires.txt +0 -0
  42. {fastcore-2.2.32 → fastcore-2.2.34}/fastcore.egg-info/top_level.txt +0 -0
  43. {fastcore-2.2.32 → fastcore-2.2.34}/pyproject.toml +0 -0
  44. {fastcore-2.2.32 → fastcore-2.2.34}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.32
3
+ Version: 2.2.34
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License-Expression: Apache-2.0
@@ -44,19 +44,19 @@ Python is a powerful, dynamic language. Rather than bake everything into the lan
44
44
 
45
45
  Here are some tips on using fastcore:
46
46
 
47
- - **Liberal imports**: Use `from fastcore.module import *` freely. The library is designed for safe wildcard imports.
48
- - **Enhanced list operations**: Substitute `list` with [`L`](https://fastcore.fast.ai/foundation.html#l). This provides advanced indexing, method chaining, and additional functionality while maintaining list-like behavior.
49
- - **Extend existing classes**: Apply the `@patch` decorator to add methods to classes, including built-ins, without subclassing.
50
- - **Streamline class initialization**: In `__init__` methods, use [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to efficiently set multiple attributes, reducing repetitive assignment code.
51
- - **Explicit keyword arguments**: Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to functions to replace `**kwargs` with specific parameters, enhancing IDE support and documentation.
52
- - **Optimize parallel execution**: Use fastcore’s enhanced [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simplified concurrent processing.
53
- - **Expressive testing**: Prefer fastcore’s testing functions like [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne), [`test_close`](https://fastcore.fast.ai/test.html#test_close) for more readable and informative test assertions.
54
- - **Advanced file operations**: Use the extended `Path` class, which adds methods like `ls()`, `read_json()`, and others to [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path).
55
- - **Flexible data structures**: Convert between dictionaries and attribute-access objects using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict) for more intuitive data handling.
56
- - **Functional programming paradigms**: Use tools like [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps), and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex) to write more functional-style Python code.
57
- - **Documentation**: Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and retains usage sections such as Notes, Raises, and Examples.
58
- - **Time-aware caching**: Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiration to the standard `lru_cache` functionality.
59
- - **Simplified CLI creation**: Use `fastcore.script` to easily transform Python functions into command-line interfaces.
47
+ - Use `from fastcore.module import *` freely. fastcore’s modules are built to be safe for wildcard imports.
48
+ - Use [`L`](https://fastcore.fast.ai/foundation.html#l) in place of `list`. [`L`](https://fastcore.fast.ai/foundation.html#l) behaves like a list, with extra indexing options, method chaining and more methods.
49
+ - Add methods to existing classes, including built-ins, with the `@patch` decorator instead of subclassing.
50
+ - In `__init__` methods, call [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to set multiple attributes at once instead of assigning each one.
51
+ - Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to show a function’s real parameters in place of `**kwargs`, for IDEs and generated documentation.
52
+ - Use fastcore’s versions of [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simpler concurrent processing.
53
+ - Prefer fastcore’s test functions, such as [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne) and [`test_close`](https://fastcore.fast.ai/test.html#test_close), for assertions that read clearly and give informative failures.
54
+ - fastcore extends [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) with methods such as `ls()` and `read_json()`.
55
+ - Convert between dictionaries and objects with attribute access using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict).
56
+ - Write in a functional style with tools such as [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps) and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex).
57
+ - Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and keeps usage sections such as Notes, Raises and Examples.
58
+ - Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiry to the standard `lru_cache`.
59
+ - Turn Python functions into command-line interfaces with `fastcore.script`.
60
60
 
61
61
  For example, [`L`](https://fastcore.fast.ai/foundation.html#l) is a drop-in replacement for `list` with extra superpowers:
62
62
 
@@ -88,8 +88,6 @@ To install fastcore run: `conda install fastcore -c fastai` (if you use Anaconda
88
88
 
89
89
  To get started, we recommend you read through [the fastcore tour](https://fastcore.fast.ai/tour.html).
90
90
 
91
- [`globtastic`](https://fastcore.fast.ai/xtras.html#globtastic) supports filename filters (`file_glob`, `file_re`) and full-path filters (`path_glob`, `path_re`). Glob filters use `fnmatch`: `*` matches directory separators and `**` has no special meaning.
92
-
93
91
  ## Contributing
94
92
 
95
93
  After you clone this repository, please run `nbdev_install_hooks` in your terminal. This sets up git hooks, which clean up the notebooks to remove the extraneous stuff stored in the notebooks (e.g. which cells you ran) which causes unnecessary merge conflicts.
@@ -13,19 +13,19 @@ Python is a powerful, dynamic language. Rather than bake everything into the lan
13
13
 
14
14
  Here are some tips on using fastcore:
15
15
 
16
- - **Liberal imports**: Use `from fastcore.module import *` freely. The library is designed for safe wildcard imports.
17
- - **Enhanced list operations**: Substitute `list` with [`L`](https://fastcore.fast.ai/foundation.html#l). This provides advanced indexing, method chaining, and additional functionality while maintaining list-like behavior.
18
- - **Extend existing classes**: Apply the `@patch` decorator to add methods to classes, including built-ins, without subclassing.
19
- - **Streamline class initialization**: In `__init__` methods, use [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to efficiently set multiple attributes, reducing repetitive assignment code.
20
- - **Explicit keyword arguments**: Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to functions to replace `**kwargs` with specific parameters, enhancing IDE support and documentation.
21
- - **Optimize parallel execution**: Use fastcore’s enhanced [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simplified concurrent processing.
22
- - **Expressive testing**: Prefer fastcore’s testing functions like [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne), [`test_close`](https://fastcore.fast.ai/test.html#test_close) for more readable and informative test assertions.
23
- - **Advanced file operations**: Use the extended `Path` class, which adds methods like `ls()`, `read_json()`, and others to [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path).
24
- - **Flexible data structures**: Convert between dictionaries and attribute-access objects using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict) for more intuitive data handling.
25
- - **Functional programming paradigms**: Use tools like [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps), and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex) to write more functional-style Python code.
26
- - **Documentation**: Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and retains usage sections such as Notes, Raises, and Examples.
27
- - **Time-aware caching**: Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiration to the standard `lru_cache` functionality.
28
- - **Simplified CLI creation**: Use `fastcore.script` to easily transform Python functions into command-line interfaces.
16
+ - Use `from fastcore.module import *` freely. fastcore’s modules are built to be safe for wildcard imports.
17
+ - Use [`L`](https://fastcore.fast.ai/foundation.html#l) in place of `list`. [`L`](https://fastcore.fast.ai/foundation.html#l) behaves like a list, with extra indexing options, method chaining and more methods.
18
+ - Add methods to existing classes, including built-ins, with the `@patch` decorator instead of subclassing.
19
+ - In `__init__` methods, call [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to set multiple attributes at once instead of assigning each one.
20
+ - Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to show a function’s real parameters in place of `**kwargs`, for IDEs and generated documentation.
21
+ - Use fastcore’s versions of [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simpler concurrent processing.
22
+ - Prefer fastcore’s test functions, such as [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne) and [`test_close`](https://fastcore.fast.ai/test.html#test_close), for assertions that read clearly and give informative failures.
23
+ - fastcore extends [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) with methods such as `ls()` and `read_json()`.
24
+ - Convert between dictionaries and objects with attribute access using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict).
25
+ - Write in a functional style with tools such as [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps) and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex).
26
+ - Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and keeps usage sections such as Notes, Raises and Examples.
27
+ - Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiry to the standard `lru_cache`.
28
+ - Turn Python functions into command-line interfaces with `fastcore.script`.
29
29
 
30
30
  For example, [`L`](https://fastcore.fast.ai/foundation.html#l) is a drop-in replacement for `list` with extra superpowers:
31
31
 
@@ -57,8 +57,6 @@ To install fastcore run: `conda install fastcore -c fastai` (if you use Anaconda
57
57
 
58
58
  To get started, we recommend you read through [the fastcore tour](https://fastcore.fast.ai/tour.html).
59
59
 
60
- [`globtastic`](https://fastcore.fast.ai/xtras.html#globtastic) supports filename filters (`file_glob`, `file_re`) and full-path filters (`path_glob`, `path_re`). Glob filters use `fnmatch`: `*` matches directory separators and `**` has no special meaning.
61
-
62
60
  ## Contributing
63
61
 
64
62
  After you clone this repository, please run `nbdev_install_hooks` in your terminal. This sets up git hooks, which clean up the notebooks to remove the extraneous stuff stored in the notebooks (e.g. which cells you ran) which causes unnecessary merge conflicts.
@@ -4,19 +4,19 @@ Python is a powerful, dynamic language. Rather than bake everything into the lan
4
4
 
5
5
  Here are some tips on using fastcore:
6
6
 
7
- - **Liberal imports**: Use `from fastcore.module import *` freely. The library is designed for safe wildcard imports.
8
- - **Enhanced list operations**: Substitute `list` with `L`. This provides advanced indexing, method chaining, and additional functionality while maintaining list-like behavior.
9
- - **Extend existing classes**: Apply the `@patch` decorator to add methods to classes, including built-ins, without subclassing.
10
- - **Streamline class initialization**: In `__init__` methods, use `store_attr()` to efficiently set multiple attributes, reducing repetitive assignment code.
11
- - **Explicit keyword arguments**: Apply the `delegates` decorator to functions to replace `**kwargs` with specific parameters, enhancing IDE support and documentation.
12
- - **Optimize parallel execution**: Use fastcore's enhanced `ThreadPoolExecutor` and `ProcessPoolExecutor` for simplified concurrent processing.
13
- - **Expressive testing**: Prefer fastcore's testing functions like `test_eq`, `test_ne`, `test_close` for more readable and informative test assertions.
14
- - **Advanced file operations**: Use the extended `Path` class, which adds methods like `ls()`, `read_json()`, and others to `pathlib.Path`.
15
- - **Flexible data structures**: Convert between dictionaries and attribute-access objects using `dict2obj` and `obj2dict` for more intuitive data handling.
16
- - **Functional programming paradigms**: Use tools like `compose`, `maps`, and `filter_ex` to write more functional-style Python code.
17
- - **Documentation**: Document parameters and return values with `docments`, using source comments or `Annotated` metadata for generated APIs. `MarkdownRenderer` shows the effective signature and retains usage sections such as Notes, Raises, and Examples.
18
- - **Time-aware caching**: Apply the `timed_cache` decorator to add time-based expiration to the standard `lru_cache` functionality.
19
- - **Simplified CLI creation**: Use `fastcore.script` to easily transform Python functions into command-line interfaces.
7
+ - Use `from fastcore.module import *` freely. fastcore's modules are built to be safe for wildcard imports.
8
+ - Use `L` in place of `list`. `L` behaves like a list, with extra indexing options, method chaining and more methods.
9
+ - Add methods to existing classes, including built-ins, with the `@patch` decorator instead of subclassing.
10
+ - In `__init__` methods, call `store_attr()` to set multiple attributes at once instead of assigning each one.
11
+ - Apply the `delegates` decorator to show a function's real parameters in place of `**kwargs`, for IDEs and generated documentation.
12
+ - Use fastcore's versions of `ThreadPoolExecutor` and `ProcessPoolExecutor` for simpler concurrent processing.
13
+ - Prefer fastcore's test functions, such as `test_eq`, `test_ne` and `test_close`, for assertions that read clearly and give informative failures.
14
+ - fastcore extends `pathlib.Path` with methods such as `ls()` and `read_json()`.
15
+ - Convert between dictionaries and objects with attribute access using `dict2obj` and `obj2dict`.
16
+ - Write in a functional style with tools such as `compose`, `maps` and `filter_ex`.
17
+ - Document parameters and return values with `docments`, using source comments or `Annotated` metadata for generated APIs. `MarkdownRenderer` shows the effective signature and keeps usage sections such as Notes, Raises and Examples.
18
+ - Apply the `timed_cache` decorator to add time-based expiry to the standard `lru_cache`.
19
+ - Turn Python functions into command-line interfaces with `fastcore.script`.
20
20
 
21
21
  For example, `L` is a drop-in replacement for `list` with extra superpowers:
22
22
 
@@ -55,4 +55,4 @@ Modules:
55
55
  - `fastcore.xml`: Concise HTML generation and namespace-aware XML construction.
56
56
  - `fastcore.xtras`: Utility functions used in the fastai library"""
57
57
 
58
- __version__ = "2.2.32"
58
+ __version__ = "2.2.34"
@@ -656,6 +656,7 @@ d = { 'settings': { 'branch': 'main',
656
656
  'fastcore.net._SafeRedirectHandler': ('net.html#_saferedirecthandler', 'fastcore/net.py'),
657
657
  'fastcore.net._SafeRedirectHandler.redirect_request': ( 'net.html#_saferedirecthandler.redirect_request',
658
658
  'fastcore/net.py'),
659
+ 'fastcore.net._http_exc': ('net.html#_http_exc', 'fastcore/net.py'),
659
660
  'fastcore.net._socket_det': ('net.html#_socket_det', 'fastcore/net.py'),
660
661
  'fastcore.net._waitfor': ('net.html#_waitfor', 'fastcore/net.py'),
661
662
  'fastcore.net.free_port': ('net.html#free_port', 'fastcore/net.py'),
@@ -9,20 +9,21 @@ from html import escape
9
9
  __all__ = ["strip_ansi", "ansi2html", "ansi2latex"]
10
10
 
11
11
  _ANSI_RE = re.compile("\x1b\\[(.*?)([@-~])")
12
+ _OSC_RE = re.compile(r'\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)')
12
13
  _ANSI_COLORS = ( "ansi-black", "ansi-red", "ansi-green", "ansi-yellow", "ansi-blue", "ansi-magenta", "ansi-cyan", "ansi-white", "ansi-black-intense",
13
14
  "ansi-red-intense", "ansi-green-intense", "ansi-yellow-intense", "ansi-blue-intense", "ansi-magenta-intense", "ansi-cyan-intense", "ansi-white-intense")
14
15
 
15
16
  def strip_terminal_queries(text):
16
- # Remove OSC sequences (like background color queries)
17
- text = re.sub('\x1b\\][^\x07]*\x07', '', text)
17
+ # Remove OSC sequences, such as hyperlinks and background color queries
18
+ text = _OSC_RE.sub('', text)
18
19
  # Remove DSR sequences (device status reports)
19
20
  return re.sub(r'\x1b\[[0-9]*n', '', text)
20
21
 
21
22
 
22
23
  def strip_ansi(source, term_queries:bool=False):
23
- "Remove ANSI escape codes from text."
24
+ "Remove ANSI escape codes, including OSC sequences such as hyperlinks, from text."
24
25
  if term_queries: source = strip_terminal_queries(source)
25
- return _ANSI_RE.sub("", source)
26
+ return _ANSI_RE.sub("", _OSC_RE.sub("", source))
26
27
 
27
28
 
28
29
  def _htmlconverter(fg, bg, bold, underline, inverse):
@@ -1,10 +1,10 @@
1
1
  """Basic functionality used in the fastai library
2
2
 
3
- The staples used throughout fastai code, each replacing a common multi-line pattern with a one-liner: `ifnone(a,b)` is `b if a is None else a` (though both args are always evaluated); `listify` and `tuplify` convert anything to a list or tuple the way you'd mean it (`None` becomes `[]`, a `str` or `dict` stays a single item, a generator is consumed); and `basic_repr('a,b')` gives a class a deterministic `key=value` repr with no memory address, so notebook and git diffs stay clean.
3
+ The staples used throughout fastai code, each replacing a common multi-line pattern with a one-liner.
4
4
 
5
5
  Curried versions of the comparison and arithmetic functions in Python's `operator` module: `lt gt le ge eq ne add sub mul truediv is_ is_not in_ mod`. With two args they work like `operator`'s versions; with one arg they return a partial that binds it as the *second* argument, so `lt(3)` means "is less than 3" and `in_(vals)` means "is contained in `vals`". They read especially well as `cmp` arguments to `fastcore.test.test`, e.g. `test(x, valid, in_)`.
6
6
 
7
- `AttrDict` is a `dict` whose keys are also attributes, so `d.foo` reads and writes `d['foo']` (to convert a whole nested structure at once, see `dict2obj` in `fastcore.xtras`); `NS` is the same idea built on `SimpleNamespace`, adding indexing and iteration. `store_attr()`, called inside `__init__`, stores the function's arguments as attributes of `self` in one line:
7
+ `store_attr()`, called inside `__init__`, stores the function's arguments as attributes of `self` in one line:
8
8
 
9
9
  ```python
10
10
  class Point:
@@ -13,7 +13,7 @@ p = Point(1, 2)
13
13
  test_eq((p.x, p.y, p.scale), (1, 2, 1))
14
14
  ```
15
15
 
16
- Tools for making and transforming functions: `compose(f,g,...)` chains functions left to right; `bind` is `partial` extended with `arg0`,`arg1`,... placeholders for reordering positional arguments; and `fail_clean` re-raises exceptions with the library's own traceback frames stripped, for errors that are part of a function's contract rather than bugs.
16
+ Utilities for functional programming or for defining, modifying, or debugging functions.
17
17
 
18
18
  `~Self` is a concise alternative to `lambda` for a function that operates on a single object (note the capitalization!). Write the chain of attribute accesses, method calls, and indexing just as you would after a variable name, with `~Self` in its place, and the result is a plain function that runs the chain on its argument:
19
19
 
@@ -25,7 +25,7 @@ Tools for making and transforming functions: `compose(f,g,...)` chains functions
25
25
 
26
26
  Since `.`, `()`, and `[]` bind tighter than `~`, the whole chain builds first and `~` then converts it to a function, so the chain never needs its own parentheses: `map(~Self.imag, nums)` works as written.
27
27
 
28
- `@patch` adds a function to an existing class as a method, using the function's `self:` type annotation to pick the class (a union annotation patches several classes at once); `@patch_to(Cls)` is the same with the class passed explicitly. Both take `as_prop`, `set_prop`, and `cls_method`. fastai code uses this to build classes incrementally across a notebook, so expect to find a class's methods defined far from the class itself:
28
+ fastai code builds classes incrementally across a notebook. A class's methods often appear far from the class itself. `@patch` adds a function to an existing class as a method, and picks the class from the function's `self:` annotation:
29
29
 
30
30
  ```python
31
31
  @patch
@@ -1314,6 +1314,7 @@ class NotStr(GetAttr):
1314
1314
  class PrettyString(str):
1315
1315
  "Little hack to get strings to show properly in Jupyter."
1316
1316
  def __repr__(self): return self
1317
+ full = True # Tools that truncate long strings show this whole
1317
1318
 
1318
1319
  # %% ../nbs/01_basics.ipynb #a5138103
1319
1320
  def even_mults(start, stop, n):
@@ -0,0 +1,62 @@
1
+ """Text, file, cell, and notebook editing from `fastcore.tools` and `fastcore.nbio`, plus the conventions the whole fastai editing toolkit follows. Read this before working with the editing tools in any package that shares them.
2
+
3
+ `from fastcore.editskill import *` loads `fastcore.tools` and `fastcore.nbio`.
4
+
5
+ ## Targets and tools
6
+
7
+ Targets: in-memory strings, file paths, notebook cell sources (`path, cell_id`), and held `Notebook`/`NbCell` objects.
8
+
9
+ - `fastcore.tools`: text primitives, file tools, and `line_hash`/`lnhash`/`lnhash_at` address creation without exhash installed.
10
+ - `fastcore.nbio`: notebook read/write/validate/repair, cell construction/editing, and `Notebook`/`NbCell` session objects with snapshot queries (`find_cells`, `summary_nb`).
11
+ - `exhash.skill`: preferred hash-verified file/cell editing where installed; covers address forms and the verified edit loop.
12
+ - `rgapi.skill`: preferred search where installed: `rg`/`fd`/`ls`/`nbrg` with lnhash output, `rgstr` for text already held.
13
+ - `remold`: structural Python search/rewrite with declarative ast-grep rules, LibCST matcher transforms and symbol queries; the engine behind `ast_replace`.
14
+ - `aidialog.dlgskill`, `dialoghelper`: preferred dialog layer where installed, including its own theory of dialogs and projections. A Solveit dialog is an `.ipynb` with notes, runnable code and prompt/reply pairs. Cell tools handle notebook structure regardless of origin; this layer reads/edits dialog messages.
15
+
16
+ Open/save: `Notebook.open(path)`, `nb.save()`. Index by position or cell id (exact/unique prefix): `nb[k]` returns a cell, `nb[k] = src` sets its source, `del nb[k]` removes it. `nb.add(src, cell_type)`/`nb.md(src)` insert at `idx`, `after` or `before` a cell id; `nb.move(ids, after=, before=)` reorders cells.
17
+
18
+ ## Naming
19
+
20
+ - File/notebook/cell/message operations: `verb_target` (`view_file`, `create_file`, `read_nb`, `write_nb`, `view_cell`, `validate_nb`, `view_msg`, `view_dlg`, `lnhashview_cell`). `find_msgs`, `add_msg`, `del_msgs`, `find_cells` need no extra dialog/notebook prefix. `msg` = dialog message; `cell` = notebook cell; `summary_nb` returns notebook-cell rows.
21
+ - Text primitives (`insert_line`, `del_lines`, `replace_lines`, `str_replace`) gain `file_`/`cell_`/`msg_` prefixes (`file_del_lines`, `cell_del_lines`, `msg_del_lines`); address arguments precede the primitive's arguments. `str_replace` retains Anthropic's text editor name/argument order. `ast_replace` (AST patterns) and `exhash` (hash-verified line addresses) use these prefixes too: `file_ast_replace`, `msg_ast_replace`, `file_exhash`, `cell_exhash`.
22
+ - Converters: `x2y` (`nb2dict`, `cell2xml`); methods: `to_y` (`nb.to_dict()`).
23
+ - Plurals accept several items: `view_cell` one cell, `lnhashview_cells` several, `del_msgs` many.
24
+
25
+ ## Parameters: shared vocabulary
26
+
27
+ - Order: address (`text`; `path`; `path, cell_id`; message `id`), new text, then keyword-only ambient context (message tools' dialog).
28
+ - `start_line`/`end_line`: 1-based, inclusive; `None` = first/last line; negative `end_line` counts from the end. `del_lines` has no defaults: state the range.
29
+ - `re_filter`/`invert_filter`: lines (not) matching a regex, like ex `g//`/`g!//`; combines with the range.
30
+ - Search patterns default to regex; editors default to literal unless `use_regex=True`.
31
+ - Views: `nums` line numbers; `lnhashs` `lineno|hash|` addresses; `maxlen` caps summary lines; `trunc_out`/`trunc_in` truncate dialog outputs/sources.
32
+ - `fd`/`ls`/`rg`/`nbrg` share one include/exclude/ext/hidden/ignore block. `fd`/`rg`/`nbrg`: `pattern` first, `root='.'` second. `ls` is `fd` with listing defaults, but `root` first, like shell `ls DIR`.
33
+ - Filters narrow with `only_*` (`only_err`, `only_exp`, `only_errors`), widen with `incl_*` (`incl_out`).
34
+ - `context=` units: file lines (blocks in summary mode), notebook cells, dialog messages.
35
+ - Editors return a diff: read it as verification rather than re-viewing. No change: fastcore editors and exhash return `none: No changes.`
36
+
37
+ ## Functions and methods
38
+
39
+ Functions take a path, save and return a diff; methods change held objects, saved explicitly. Methods drop address arguments and the object's part of the name: `cell_str_replace(path, cell_id, ...)` -> `c.str_replace(...)` on `NbCell`; `find_cells(path, pat)` -> `nb.find_cells(pat)` on `Notebook`. Read functions return snapshot rows (addresses, source, metadata); read methods return objects. One style per file: save before switching to functions; reopen before returning to methods.
40
+
41
+ ## Navigation and addresses
42
+
43
+ When unsure where to edit, start with summaries: rgapi's `rg(summary=True)`/`nbrg`, aidialog's `summary_dlg`, exhash's `open_doc` outlines. They give one addressed row per block/cell/message/section. `open_doc` outlines Markdown, code and notebooks; `doc(open_doc)` covers inputs, navigation and llms.txt. A section is a span of lines or a run of cells, edited through file/cell tools. Token `1.6.|12|Py|,45|HD|` combines section number and first/last-line lnhash range; the range is an exhash address.
44
+
45
+ Edits take plain line numbers or lnhash addresses obtained while reading: `nums=True`/`lnhashs=True` views, `rg(lnhashs=True)`. Prefer lnhash addresses where exhash is installed; stale ones are rejected. Plain numbers are unverified and shift: re-view after each such edit; apply several bottom-to-top.
46
+
47
+ Docs: https://fastcore.fast.ai/tools.html.md and https://fastcore.fast.ai/nbio.html.md
48
+ """
49
+
50
+ from fastcore.tools import (insert_line, str_replace, strs_replace, replace_lines, del_lines, ast_replace,
51
+ file_insert_line, file_str_replace, file_strs_replace, file_replace_lines, file_del_lines, file_ast_replace,
52
+ view_file, create_file, line_hash, lnhash, lnhash_at)
53
+ from fastcore.nbio import (read_nb, write_nb, new_nb, mk_cell, validate_nb, validate_cell, repair_nb, repair_cell,
54
+ view_cell, cell_insert_line, cell_str_replace, cell_strs_replace, cell_replace_lines, cell_del_lines, cell_ast_replace, Notebook, NbCell, find_cells, summary_nb)
55
+
56
+ __all__ = ['insert_line', 'str_replace', 'strs_replace', 'replace_lines', 'del_lines', 'ast_replace',
57
+ 'file_insert_line', 'file_str_replace', 'file_strs_replace', 'file_replace_lines', 'file_del_lines', 'file_ast_replace',
58
+ 'view_file', 'create_file', 'line_hash', 'lnhash', 'lnhash_at',
59
+ 'read_nb', 'write_nb', 'new_nb', 'mk_cell', 'validate_nb', 'validate_cell', 'repair_nb', 'repair_cell',
60
+ 'view_cell', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace', 'cell_replace_lines', 'cell_del_lines', 'cell_ast_replace', 'Notebook', 'NbCell', 'find_cells', 'summary_nb']
61
+
62
+ __pyskill_params__ = {'replace_params': ('start_line', 'end_line', 'n_matches', 're_filter', 'invert_filter', 'use_regex')}
@@ -219,10 +219,9 @@ def _nm_map(nms):
219
219
  return py2orig
220
220
 
221
221
  # %% ../nbs/14_funccall.ipynb #47b49644
222
- def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
223
- "Call the function `fc_name` with the given `fc_inputs` using namespace `ns`."
224
- if not isinstance(ns, abc.Mapping): ns = mk_ns(ns)
225
- func = resolve_nm(fc_name, ns)
222
+ def call_func(fc_name, fc_inputs, ns=None, raise_on_err=True):
223
+ "Call `fc_name`, a function or its name in namespace `ns`, with the given `fc_inputs`."
224
+ func = resolve_nm(fc_name, mk_ns(ns)) if isinstance(fc_name, str) else fc_name
226
225
  inps = {_norm_nm(k):v for k,v in fc_inputs.items()}
227
226
  inps = coerce_inputs(func, inps)
228
227
  try: return func(**inps)
@@ -231,17 +230,12 @@ def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
231
230
  else: return traceback.format_exc()
232
231
 
233
232
  # %% ../nbs/14_funccall.ipynb #73bca085
234
- async def call_func_async(fc_name, fc_inputs, ns, raise_on_err=True):
235
- "Awaits the function `fc_name` with the given `fc_inputs` using namespace `ns`."
236
- if not isinstance(ns, abc.Mapping): ns = mk_ns(ns)
237
- func = resolve_nm(fc_name, ns)
238
- try:
239
- res = call_func(fc_name, fc_inputs, ns, raise_on_err=raise_on_err)
240
- res = await maybe_await(res)
233
+ async def call_func_async(fc_name, fc_inputs, ns=None, raise_on_err=True):
234
+ "Awaits `fc_name`, a function or its name in namespace `ns`, with the given `fc_inputs`."
235
+ try: return await maybe_await(call_func(fc_name, fc_inputs, ns, raise_on_err=raise_on_err))
241
236
  except Exception as e:
242
237
  if raise_on_err: raise e from None
243
238
  else: return traceback.format_exc()
244
- return res
245
239
 
246
240
  # %% ../nbs/14_funccall.ipynb #5a2588d5
247
241
  type_map = dict(string=str, boolean=bool, integer=int, number=float, array=list, object=dict)
@@ -1,10 +1,10 @@
1
1
  """Reading, writing, and running Jupyter notebooks
2
2
 
3
- Cell tools apply `fastcore.tools`' string editing primitives to one notebook cell's source, addressed by path and cell id, mirroring that module's file tools: the same operations and parameters, with `path, cell_id` in place of `path`. Each editor (including the structural `cell_ast_replace`) returns a diff of the change, and `view_cell` shows a cell's source with optional line numbers or exhash addresses.
3
+ The cell tools apply `fastcore.tools`' string editing primitives to one notebook cell's source. They match that module's file tools, with the same operations and parameters, but take `path, cell_id` where the file tools take `path`. Every editor, including the structural `cell_ast_replace`, returns a diff of its change. `view_cell` shows a cell's source with optional line numbers or exhash addresses.
4
4
 
5
- Naming and parameter conventions shared across the editing toolkit are documented in `fastcore.editskill`, which also re-exports this module's editing tools.
5
+ `fastcore.editskill` documents the naming and parameter conventions shared across the editing toolkit, and re-exports this module's editing tools.
6
6
 
7
- `diff_cells` compares two versions of a cell sequence -- an open notebook against its file on disk, a dialog against an edited copy -- and yields the edits that turn one into the other. Items are aligned by `id` (any objects with `.id` work, not just cells), and each edit is a *block*: a contiguous run of deletions, insertions, or in-place changes, so an applier can handle a whole run at once and inserted items keep their order. Identity questions ride the ids; whether an aligned pair *changed* is a content question, answered by comparing `key(item)` on each side.
7
+ `diff_cells` compares two versions of a cell sequence, such as an open notebook and its file on disk, or a dialog and an edited copy. It yields the edits that turn one into the other. It aligns items by `id`, and works with any objects that have an `.id`, not just cells. Each edit is a *block* covering a contiguous run of deletions, insertions or in-place changes. An applier can handle each block in one step, keeping inserted items in order. An aligned pair counts as changed when `key(item)` differs between the two sides.
8
8
 
9
9
  Docs: https://fastcore.fast.ai/nbio.html.md"""
10
10
 
@@ -799,9 +799,10 @@ def to_dict(self:Notebook):
799
799
  class Found:
800
800
  "Mixin for find-result containers: `matched` ids, id-only indexing, and match/context kinds"
801
801
  _unit = 'item'
802
- def __init__(self, items=None, matched=None):
802
+ def __init__(self, items=None, matched=None, maxlen=MAXLEN):
803
803
  super().__init__(items if items is not None else [])
804
804
  self.matched = set(matched) if matched is not None else {o.id for o in self}
805
+ self.maxlen = maxlen
805
806
  def kind(self, o): return 'match' if o.id in self.matched else 'context'
806
807
  def __getitem__(self, k):
807
808
  if not isinstance(k, str): raise TypeError(
@@ -814,7 +815,7 @@ class FoundCells(Found, list):
814
815
  "Find results: cells indexed by id (exact or unique prefix), shown as `CellRow` lines with context rows marked"
815
816
  _unit = 'cell'
816
817
  def __repr__(self):
817
- rows = [c if isinstance(c, CellRow) else CellRow(c) for c in self]
818
+ rows = [c if isinstance(c, CellRow) else CellRow(c, self.maxlen) for c in self]
818
819
  for r in rows: r.kind = self.kind(r)
819
820
  return '\n'.join(repr(r) for r in rows)
820
821
 
@@ -825,6 +826,7 @@ def find_cells(self:Notebook,
825
826
  cell_type:str=None, # Optional limit by type ('code', 'markdown', or 'raw')
826
827
  ids='', # Optional limit by cell ids (comma-separated str, or list); exact or unique prefixes
827
828
  context:int=None, # Cells of context around matches (default 1)
829
+ maxlen:int=MAXLEN, # Maximum source characters per displayed cell
828
830
  ):
829
831
  "Find live cells matching all the given criteria, plus `context` neighbouring cells"
830
832
  if context is None: context = 1
@@ -832,7 +834,7 @@ def find_cells(self:Notebook,
832
834
  cs = self.cells
833
835
  idxs = [i for i,c in enumerate(cs) if (not pat or re.search(pat, c.source)) and (not cell_type or c.cell_type==cell_type) and (not ids or c.id in ids)]
834
836
  keep = sorted({j for i in idxs for j in range(max(0,i-context), min(len(cs),i+context+1))})
835
- return FoundCells([cs[j] for j in keep], matched={cs[i].id for i in idxs})
837
+ return FoundCells([cs[j] for j in keep], matched={cs[i].id for i in idxs}, maxlen=maxlen)
836
838
 
837
839
  # %% ../nbs/13_nbio.ipynb #cb639e77
838
840
  def find_cells(
@@ -841,10 +843,11 @@ def find_cells(
841
843
  cell_type:str=None, # Optional limit by type ('code', 'markdown', or 'raw')
842
844
  ids='', # Optional limit by cell ids (comma-separated str, or list); exact or unique prefixes
843
845
  context:int=None, # Cells of context around matches (default 1)
846
+ maxlen:int=MAXLEN, # Maximum source characters per displayed cell
844
847
  ):
845
848
  "Snapshot `FoundCells` for matching cells in the notebook at `path`"
846
849
  fc = Notebook.open(path).find_cells(pat, cell_type, ids=ids, context=context)
847
- return FoundCells([CellRow(c) for c in fc], matched=fc.matched)
850
+ return FoundCells([CellRow(c, maxlen) for c in fc], matched=fc.matched)
848
851
 
849
852
  # %% ../nbs/13_nbio.ipynb #202a29f1
850
853
  def deep_merge(
@@ -1,6 +1,6 @@
1
1
  """Network, HTTP, and URL functions
2
2
 
3
- `urlread`/`urljson` retrieve a URL (POSTing when `data` or kwargs are given), `urlsave` downloads to a file named from the URL, and `urlopen` wraps `urllib` with quoting, header, and data handling; on HTTP failure they raise a status-specific exception (`HTTP404NotFoundError`, ...), each a subclass of `HTTP4xxClientError` or `HTTP5xxServerError`, with the response body included in the message. `start_server`/`start_client` make TCP — or, passing a string `port`, Unix-socket — connections; `waitfor` polls a callable until truthy with a timeout; and `is_port_free`/`wait_port_free` help coordinate with servers.
3
+ Every URL function here goes through `urlopen`. It quotes the URL, sends `url_default_headers`, and encodes `data`. On an HTTP error it raises the status-specific exception for the code, such as `HTTP404NotFoundError` or `HTTP503ServiceUnavailableError`. Each is a subclass of `HTTP4xxClientError` or `HTTP5xxServerError`. Its message includes the response body. The module also has TCP and Unix-socket clients and servers, and helpers that wait for a condition or a free port.
4
4
 
5
5
  Docs: https://fastcore.fast.ai/net.html.md"""
6
6
 
@@ -19,7 +19,11 @@ __all__ = ['url_default_headers', 'ExceptionsHTTP', 'urlquote', 'urlwrap', 'HTTP
19
19
  'HTTP418AmAteapotError', 'HTTP421MisdirectedRequestError', 'HTTP422UnprocessableEntityError',
20
20
  'HTTP423LockedError', 'HTTP424FailedDependencyError', 'HTTP425TooEarlyError', 'HTTP426UpgradeRequiredError',
21
21
  'HTTP428PreconditionRequiredError', 'HTTP429TooManyRequestsError', 'HTTP431HeaderFieldsTooLargeError',
22
- 'HTTP451LegalReasonsError']
22
+ 'HTTP451LegalReasonsError', 'HTTP500InternalServerError', 'HTTP501NotImplementedError',
23
+ 'HTTP502BadGatewayError', 'HTTP503ServiceUnavailableError', 'HTTP504GatewayTimeoutError',
24
+ 'HTTP505HTTPVersionNotSupportedError', 'HTTP506VariantAlsoNegotiatesError',
25
+ 'HTTP507InsufficientStorageError', 'HTTP508LoopDetectedError', 'HTTP510NotExtendedError',
26
+ 'HTTP511NetworkAuthenticationRequiredError']
23
27
 
24
28
  # %% ../nbs/03b_net.ipynb #05c808e7
25
29
  from .utils import *
@@ -99,18 +103,28 @@ _httperrors = ((400,'Bad Request'),(401,'Unauthorized'),(402,'Payment Required')
99
103
  (414,'URI Too Long'),(415,'Unsupported Media Type'),(416,'Range Not Satisfiable'),(417,'Expectation Failed'),
100
104
  (418,'Am A teapot'),(421,'Misdirected Request'),(422,'Unprocessable Entity'),(423,'Locked'),(424,'Failed Dependency'),
101
105
  (425,'Too Early'),(426,'Upgrade Required'),(428,'Precondition Required'),(429,'Too Many Requests'),
102
- (431,'Header Fields Too Large'),(451,'Legal Reasons'))
106
+ (431,'Header Fields Too Large'),(451,'Legal Reasons'),(500,'Internal Server Error'),(501,'Not Implemented'),
107
+ (502,'Bad Gateway'),(503,'Service Unavailable'),(504,'Gateway Timeout'),(505,'HTTP Version Not Supported'),
108
+ (506,'Variant Also Negotiates'),(507,'Insufficient Storage'),(508,'Loop Detected'),(510,'Not Extended'),
109
+ (511,'Network Authentication Required'))
103
110
 
104
111
  for code,msg in _httperrors:
105
- nm = f'HTTP{code}{msg.replace(" ","")}Error'
106
- def _init(self, url, hdrs, fp, msg=msg, code=code): HTTP4xxClientError.__init__(self, url, code, msg, hdrs, fp)
107
- cls = type(nm, (HTTP4xxClientError,), {'__init__':_init})
112
+ base = HTTP4xxClientError if code<500 else HTTP5xxServerError
113
+ nm = f'HTTP{code}{msg.replace(" ","").removesuffix("Error")}Error'
114
+ def _init(self, url, hdrs, fp, msg=msg, code=code, base=base): base.__init__(self, url, code, msg, hdrs, fp)
115
+ cls = type(nm, (base,), {'__init__':_init})
108
116
  globals()[nm] = ExceptionsHTTP[code] = cls
109
117
 
110
118
  # %% ../nbs/03b_net.ipynb #21fa32a4
111
- _all_ = ['HTTP400BadRequestError', 'HTTP401UnauthorizedError', 'HTTP402PaymentRequiredError', 'HTTP403ForbiddenError', 'HTTP404NotFoundError', 'HTTP405MethodNotAllowedError', 'HTTP406NotAcceptableError', 'HTTP407ProxyAuthRequiredError', 'HTTP408RequestTimeoutError', 'HTTP409ConflictError', 'HTTP410GoneError', 'HTTP411LengthRequiredError', 'HTTP412PreconditionFailedError', 'HTTP413PayloadTooLargeError', 'HTTP414URITooLongError', 'HTTP415UnsupportedMediaTypeError', 'HTTP416RangeNotSatisfiableError', 'HTTP417ExpectationFailedError', 'HTTP418AmAteapotError', 'HTTP421MisdirectedRequestError', 'HTTP422UnprocessableEntityError', 'HTTP423LockedError', 'HTTP424FailedDependencyError', 'HTTP425TooEarlyError', 'HTTP426UpgradeRequiredError', 'HTTP428PreconditionRequiredError', 'HTTP429TooManyRequestsError', 'HTTP431HeaderFieldsTooLargeError', 'HTTP451LegalReasonsError']
119
+ _all_ = ['HTTP400BadRequestError', 'HTTP401UnauthorizedError', 'HTTP402PaymentRequiredError', 'HTTP403ForbiddenError', 'HTTP404NotFoundError', 'HTTP405MethodNotAllowedError', 'HTTP406NotAcceptableError', 'HTTP407ProxyAuthRequiredError', 'HTTP408RequestTimeoutError', 'HTTP409ConflictError', 'HTTP410GoneError', 'HTTP411LengthRequiredError', 'HTTP412PreconditionFailedError', 'HTTP413PayloadTooLargeError', 'HTTP414URITooLongError', 'HTTP415UnsupportedMediaTypeError', 'HTTP416RangeNotSatisfiableError', 'HTTP417ExpectationFailedError', 'HTTP418AmAteapotError', 'HTTP421MisdirectedRequestError', 'HTTP422UnprocessableEntityError', 'HTTP423LockedError', 'HTTP424FailedDependencyError', 'HTTP425TooEarlyError', 'HTTP426UpgradeRequiredError', 'HTTP428PreconditionRequiredError', 'HTTP429TooManyRequestsError', 'HTTP431HeaderFieldsTooLargeError', 'HTTP451LegalReasonsError', 'HTTP500InternalServerError', 'HTTP501NotImplementedError', 'HTTP502BadGatewayError', 'HTTP503ServiceUnavailableError', 'HTTP504GatewayTimeoutError', 'HTTP505HTTPVersionNotSupportedError', 'HTTP506VariantAlsoNegotiatesError', 'HTTP507InsufficientStorageError', 'HTTP508LoopDetectedError', 'HTTP510NotExtendedError', 'HTTP511NetworkAuthenticationRequiredError']
112
120
 
113
121
  # %% ../nbs/03b_net.ipynb #0d72881c
122
+ def _http_exc(e):
123
+ "The status-specific exception for `HTTPError` `e`, or `e` itself outside 4xx and 5xx"
124
+ if e.code in ExceptionsHTTP: return ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg)
125
+ if 400 <= e.code < 600: return (HTTP4xxClientError if e.code<500 else HTTP5xxServerError)(e.url, e.code, e.msg, e.hdrs, e.fp)
126
+ return e
127
+
114
128
  def urlopen(url, data=None, headers=None, timeout=None, **kwargs):
115
129
  "Like `urllib.request.urlopen`, but first `urlwrap` the `url`, and encode `data`"
116
130
  if kwargs and not data: data=kwargs
@@ -118,18 +132,14 @@ def urlopen(url, data=None, headers=None, timeout=None, **kwargs):
118
132
  if not isinstance(data, strtyps): data = urlencode(data)
119
133
  if not isinstance(data, bytes): data = data.encode('ascii')
120
134
  try: return urlopener().open(urlwrap(url, data=data, headers=headers), timeout=timeout)
121
- except HTTPError as e:
135
+ except HTTPError as e:
122
136
  e.msg += f"\n====Error Body====\n{e.read().decode(errors='ignore')}"
123
- raise
137
+ raise _http_exc(e) from None
124
138
 
125
139
  # %% ../nbs/03b_net.ipynb #fa6a4dfe
126
140
  def urlread(url, data=None, headers=None, decode=True, return_json=False, return_headers=False, timeout=None, **kwargs):
127
141
  "Retrieve `url`, using `data` dict or `kwargs` to `POST` if present"
128
- try:
129
- with urlopen(url, data=data, headers=headers, timeout=timeout, **kwargs) as u: res,hdrs = u.read(),u.headers
130
- except HTTPError as e:
131
- if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg) from None
132
- else: raise
142
+ with urlopen(url, data=data, headers=headers, timeout=timeout, **kwargs) as u: res,hdrs = u.read(),u.headers
133
143
 
134
144
  if decode: res = res.decode()
135
145
  if return_json: res = loads(res)
@@ -1,6 +1,6 @@
1
1
  """Fast styling for friendly CLIs.
2
2
 
3
- Build ANSI terminal styles by chaining attributes on the exported `S` object, then apply by calling with a string: `S.blue.bold('hi')` returns the escaped string, nesting correctly inside other styles. Chains are plain objects, so a style can be defined once and reused; tab completion on `S.` lists the available colors and effects.
3
+ Build an ANSI terminal style by chaining attributes on the exported `S` object, then apply it by calling it with a string. `S.blue.bold('hi')` returns the escaped string, which nests correctly inside other styles. A chain is a plain object that can be defined once and reused. Tab completion on `S.` lists the available colors and effects.
4
4
 
5
5
  Docs: https://fastcore.fast.ai/style.html.md"""
6
6
 
@@ -1,6 +1,6 @@
1
1
  """Helper functions to quickly write tests in notebooks
2
2
 
3
- All the helpers here wrap `test(a,b,cmp)`: an `assert cmp(a,b)` that shows both values when the comparison fails, rather than a bare `AssertionError`. The named comparisons are `test_eq`, `test_ne`, `test_eq_type` (equal and same type), `test_close` (within `eps`, default 1e-5), `test_is`, `test_shuffled` (equal ignoring order), `test_stdout` (what `f` prints), and `test_warns`.
3
+ All the helpers here wrap `test(a,b,cmp)`, an `assert cmp(a,b)` that shows both values when the comparison fails, rather than a bare `AssertionError`.
4
4
 
5
5
  To check that code fails as expected, use `test_fail(f, contains=..., exc=...)` for a callable, or `expect_fail` as a context manager, which also accepts `regex`:
6
6
 
@@ -1,6 +1,6 @@
1
1
  """XDG Base Directory Specification helpers.
2
2
 
3
- `xdg_cache_home`, `xdg_config_home`, `xdg_data_home`, `xdg_state_home`, and `xdg_runtime_dir` each return the `Path` given by their `XDG_*` environment variable, falling back to the [spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)'s default (`~/.cache`, `~/.config`, `~/.local/share`, `~/.local/state`; `None` for the runtime dir) when it's unset, empty, or relative. `xdg_config_dirs` and `xdg_data_dirs` likewise return the colon-split search-path lists.
3
+ Each helper reads one `XDG_*` environment variable and falls back to the [spec](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)'s default when the variable is unset or empty. The single-path helpers also fall back when the variable holds a relative path. The `*_DIRS` helpers split the variable on colons and drop relative entries. `xdg_runtime_dir` has no default and returns `None`.
4
4
 
5
5
  Docs: https://fastcore.fast.ai/xdg.html.md"""
6
6
 
@@ -158,6 +158,7 @@ def Html(*c, doctype=True, **kwargs)->FT:
158
158
  # %% ../nbs/09_xml.ipynb #116c886e
159
159
  class Safe(str):
160
160
  def __html__(self): return self
161
+ full = True # Tools that truncate long strings show this whole
161
162
 
162
163
  # %% ../nbs/09_xml.ipynb #254c8ff3
163
164
  def _escape(s):
@@ -258,7 +258,7 @@ def detect_mime(data):
258
258
  import mimetypes
259
259
  from fastcore import imghdr
260
260
  for (sig,pos),mime in _sigs.items():
261
- if data[pos:pos+len(sig)]==sig: return mime(data) if callable(mime) else mime
261
+ if data[pos:pos+len(sig)]==sig and (res := mime(data) if callable(mime) else mime): return res
262
262
  return mimetypes.types_map.get(f'.{imghdr.what(None, h=data)}')
263
263
 
264
264
  # %% ../nbs/03_xtras.ipynb #f856746a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcore
3
- Version: 2.2.32
3
+ Version: 2.2.34
4
4
  Summary: Python supercharged for fastai development
5
5
  Author-email: Jeremy Howard and Sylvain Gugger <infos@fast.ai>
6
6
  License-Expression: Apache-2.0
@@ -44,19 +44,19 @@ Python is a powerful, dynamic language. Rather than bake everything into the lan
44
44
 
45
45
  Here are some tips on using fastcore:
46
46
 
47
- - **Liberal imports**: Use `from fastcore.module import *` freely. The library is designed for safe wildcard imports.
48
- - **Enhanced list operations**: Substitute `list` with [`L`](https://fastcore.fast.ai/foundation.html#l). This provides advanced indexing, method chaining, and additional functionality while maintaining list-like behavior.
49
- - **Extend existing classes**: Apply the `@patch` decorator to add methods to classes, including built-ins, without subclassing.
50
- - **Streamline class initialization**: In `__init__` methods, use [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to efficiently set multiple attributes, reducing repetitive assignment code.
51
- - **Explicit keyword arguments**: Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to functions to replace `**kwargs` with specific parameters, enhancing IDE support and documentation.
52
- - **Optimize parallel execution**: Use fastcore’s enhanced [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simplified concurrent processing.
53
- - **Expressive testing**: Prefer fastcore’s testing functions like [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne), [`test_close`](https://fastcore.fast.ai/test.html#test_close) for more readable and informative test assertions.
54
- - **Advanced file operations**: Use the extended `Path` class, which adds methods like `ls()`, `read_json()`, and others to [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path).
55
- - **Flexible data structures**: Convert between dictionaries and attribute-access objects using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict) for more intuitive data handling.
56
- - **Functional programming paradigms**: Use tools like [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps), and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex) to write more functional-style Python code.
57
- - **Documentation**: Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and retains usage sections such as Notes, Raises, and Examples.
58
- - **Time-aware caching**: Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiration to the standard `lru_cache` functionality.
59
- - **Simplified CLI creation**: Use `fastcore.script` to easily transform Python functions into command-line interfaces.
47
+ - Use `from fastcore.module import *` freely. fastcore’s modules are built to be safe for wildcard imports.
48
+ - Use [`L`](https://fastcore.fast.ai/foundation.html#l) in place of `list`. [`L`](https://fastcore.fast.ai/foundation.html#l) behaves like a list, with extra indexing options, method chaining and more methods.
49
+ - Add methods to existing classes, including built-ins, with the `@patch` decorator instead of subclassing.
50
+ - In `__init__` methods, call [`store_attr()`](https://fastcore.fast.ai/basics.html#store_attr) to set multiple attributes at once instead of assigning each one.
51
+ - Apply the [`delegates`](https://fastcore.fast.ai/meta.html#delegates) decorator to show a function’s real parameters in place of `**kwargs`, for IDEs and generated documentation.
52
+ - Use fastcore’s versions of [`ThreadPoolExecutor`](https://fastcore.fast.ai/parallel.html#threadpoolexecutor) and [`ProcessPoolExecutor`](https://fastcore.fast.ai/parallel.html#processpoolexecutor) for simpler concurrent processing.
53
+ - Prefer fastcore’s test functions, such as [`test_eq`](https://fastcore.fast.ai/test.html#test_eq), [`test_ne`](https://fastcore.fast.ai/test.html#test_ne) and [`test_close`](https://fastcore.fast.ai/test.html#test_close), for assertions that read clearly and give informative failures.
54
+ - fastcore extends [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path) with methods such as `ls()` and `read_json()`.
55
+ - Convert between dictionaries and objects with attribute access using [`dict2obj`](https://fastcore.fast.ai/xtras.html#dict2obj) and [`obj2dict`](https://fastcore.fast.ai/xtras.html#obj2dict).
56
+ - Write in a functional style with tools such as [`compose`](https://fastcore.fast.ai/basics.html#compose), [`maps`](https://fastcore.fast.ai/basics.html#maps) and [`filter_ex`](https://fastcore.fast.ai/basics.html#filter_ex).
57
+ - Document parameters and return values with [`docments`](https://fastcore.fast.ai/docments.html#docments), using source comments or `Annotated` metadata for generated APIs. [`MarkdownRenderer`](https://fastcore.fast.ai/docments.html#markdownrenderer) shows the effective signature and keeps usage sections such as Notes, Raises and Examples.
58
+ - Apply the [`timed_cache`](https://fastcore.fast.ai/xtras.html#timed_cache) decorator to add time-based expiry to the standard `lru_cache`.
59
+ - Turn Python functions into command-line interfaces with `fastcore.script`.
60
60
 
61
61
  For example, [`L`](https://fastcore.fast.ai/foundation.html#l) is a drop-in replacement for `list` with extra superpowers:
62
62
 
@@ -88,8 +88,6 @@ To install fastcore run: `conda install fastcore -c fastai` (if you use Anaconda
88
88
 
89
89
  To get started, we recommend you read through [the fastcore tour](https://fastcore.fast.ai/tour.html).
90
90
 
91
- [`globtastic`](https://fastcore.fast.ai/xtras.html#globtastic) supports filename filters (`file_glob`, `file_re`) and full-path filters (`path_glob`, `path_re`). Glob filters use `fnmatch`: `*` matches directory separators and `**` has no special meaning.
92
-
93
91
  ## Contributing
94
92
 
95
93
  After you clone this repository, please run `nbdev_install_hooks` in your terminal. This sets up git hooks, which clean up the notebooks to remove the extraneous stuff stored in the notebooks (e.g. which cells you ran) which causes unnecessary merge conflicts.
@@ -1,64 +0,0 @@
1
- """Text, file, cell, and notebook editing from `fastcore.tools` and `fastcore.nbio`, plus the conventions the whole fastai editing toolkit follows. Read this before working with the editing tools in any package that shares them.
2
-
3
- `from fastcore.editskill import *` loads `fastcore.tools` (text primitives, file tools) and `fastcore.nbio` (notebook I/O, cell editors). Where installed, prefer `exhash` for hash-verified editing, `rgapi` for search, and `aidialog`/`dialoghelper` for dialogs.
4
-
5
- ## Places
6
-
7
- Targets: strings in memory, files (a path), notebook cells (`path, cell_id`; edits that cell's source), and in-memory `Notebook`/`NbCell`. A Solveit dialog is an `.ipynb` whose cells are notes, runnable code, and prompt/reply pairs; cell tools work with notebook structure whatever produced the file, while `aidialog.dlgskill`/`dialoghelper` read and edit dialog messages. exhash's `open_doc` outlines Markdown, code, and notebooks (`doc(open_doc)`: inputs, navigation, llms.txt workflow); a section is a span of lines or a run of cells, changed with the file and cell tools.
8
-
9
- Open a `Notebook` with `Notebook.open(path)` and save it with `nb.save()`. Index it by position or cell id (exact or unique prefix): `nb[k]` returns a cell, `nb[k] = src` sets its source, and `del nb[k]` removes it. `nb.add(src, cell_type)` and `nb.md(src)` insert a cell at `idx`, or `after` or `before` a cell id. `nb.move(ids, after=, before=)` reorders cells.
10
-
11
- ## Naming
12
-
13
- - Operations on files, notebooks, cells, and messages: `verb_target` (`view_file`, `create_file`, `read_nb`, `write_nb`, `view_cell`, `validate_nb`, `view_msg`, `view_dlg`, `lnhashview_cell`). `find_msgs`, `add_msg`, `del_msgs`, `find_cells` need no extra dialog/notebook prefix. `msg` = dialog message; `cell` = notebook cell. `summary_nb` returns rows for notebook cells.
14
- - Text primitives (`insert_line`, `del_lines`, `replace_lines`, `str_replace`) get `file_`/`cell_`/`msg_` versions (`file_del_lines`, `cell_del_lines`, `msg_del_lines`) that take the primitive's arguments after their address arguments. `str_replace` keeps the name and argument order of Anthropic's text editor tool. `ast_replace` (AST patterns) and `exhash` (hash-verified line addresses) use the same prefixes: `file_ast_replace`, `msg_ast_replace`, `file_exhash`, `cell_exhash`.
15
- - Converters: `x2y` (`nb2dict`, `cell2xml`, aidialog's `dlg2md`); converter methods: `to_y` (`nb.to_dict()`).
16
- - Plural names take several items: `view_cell` one cell, `lnhashview_cells` several, `del_msgs` many.
17
-
18
- ## Parameters (one vocabulary wherever it appears)
19
-
20
- - Order: the place's address (`text`; `path`; `path, cell_id`; a message `id`), then the new text, then ambient context as keyword-only (how message tools name their dialog).
21
- - `start_line`/`end_line`: 1-based, inclusive, `None` = first/last line; a negative `end_line` counts from the end. `del_lines` has no defaults: state the range.
22
- - `re_filter`/`invert_filter`: restrict an edit to lines (not) matching a regex, like ex `g//`/`g!//`; combines with the range.
23
- - Searches read patterns as regex by default; editors read them as literal text unless `use_regex=True`.
24
- - Views: `nums` (line numbers), `lnhashs` (`lineno|hash|` addresses); `maxlen` caps summary lines; `trunc_out`/`trunc_in` truncate outputs/sources in dialog views.
25
- - Search tools (`fd`, `ls`, `rg`, `nbrg`): `pattern` first, `root='.'`, one include/exclude/ext/hidden/ignore block; variants differ by defaults, not API (`ls` is `fd` with listing defaults).
26
- - Boolean filters narrow as `only_*` (`only_err`, `only_exp`, `only_errors`) and widen as `incl_*` (`incl_out`).
27
- - `context=` counts the place's units: lines (blocks in summary mode) for files, cells for notebooks, messages for dialogs.
28
- - Editors return a diff, which is the verification: read it rather than re-viewing. No change: fastcore editors and exhash return `none: No changes.`
29
-
30
- ## Functions and methods
31
-
32
- Functions take a path, save, and return a diff; methods change an object in memory, saved explicitly. Methods drop the address arguments and the object's part of the name: `cell_str_replace(path, cell_id, ...)` -> `c.str_replace(...)` on an `NbCell`; `find_cells(path, pat)` -> `nb.find_cells(pat)` on a `Notebook`. Read functions return snapshot rows (addresses, source, metadata); read methods return the objects. One style per file at a time: save before switching to functions, reopen before returning to methods.
33
-
34
- ## Addresses
35
-
36
- Edits take plain line numbers or lnhash addresses, got while reading: `nums=True`/`lnhashs=True` views, `rg(lnhashs=True)`. Prefer lnhash addresses where exhash is installed; stale ones are rejected. Plain line numbers are unverified and shift, so re-view after each such edit and apply several bottom-to-top. `exhash.skill` covers address forms and the verified edit loop.
37
-
38
- Not sure where to edit? Start with a summary: rgapi's `rg(summary=True)` and `nbrg`, aidialog's `summary_dlg`, and exhash's `open_doc` outlines give one addressed row per block, cell, message, or section. A section token such as `1.6.|12|Py|,45|HD|` is the section number plus the lnhash range of the section's first and last lines; that range works as an exhash address.
39
-
40
- ## What's where
41
-
42
- - `fastcore.tools`: text primitives, file tools, and `line_hash`/`lnhash`/`lnhash_at` for creating addresses without exhash installed.
43
- - `fastcore.nbio`: notebook read/write/validate/repair, cell construction, cell editors, and the `Notebook`/`NbCell` session objects with their snapshot queries (`find_cells`, `summary_nb`).
44
- - `exhash.skill`: hash-verified editing for files and cells, plus `open_doc` section outlines for Markdown, code, and notebooks; prefer it for edits where installed.
45
- - `rgapi.skill`: `rg`/`fd`/`ls`/`nbrg` search with lnhash output, and `rgstr` to search text already in hand.
46
- - `remold`: structural search and rewrite for Python source (declarative ast-grep rules, LibCST matcher transforms, symbol queries); the engine behind `ast_replace`.
47
- - `aidialog.dlgskill`, `dialoghelper`: the dialog layer, including its own theory of dialogs and projections.
48
-
49
- Docs: https://fastcore.fast.ai/tools.html.md and https://fastcore.fast.ai/nbio.html.md
50
- """
51
-
52
- from fastcore.tools import (insert_line, str_replace, strs_replace, replace_lines, del_lines, ast_replace,
53
- file_insert_line, file_str_replace, file_strs_replace, file_replace_lines, file_del_lines, file_ast_replace,
54
- view_file, create_file, line_hash, lnhash, lnhash_at)
55
- from fastcore.nbio import (read_nb, write_nb, new_nb, mk_cell, validate_nb, validate_cell, repair_nb, repair_cell,
56
- view_cell, cell_insert_line, cell_str_replace, cell_strs_replace, cell_replace_lines, cell_del_lines, cell_ast_replace, Notebook, NbCell, find_cells, summary_nb)
57
-
58
- __all__ = ['insert_line', 'str_replace', 'strs_replace', 'replace_lines', 'del_lines', 'ast_replace',
59
- 'file_insert_line', 'file_str_replace', 'file_strs_replace', 'file_replace_lines', 'file_del_lines', 'file_ast_replace',
60
- 'view_file', 'create_file', 'line_hash', 'lnhash', 'lnhash_at',
61
- 'read_nb', 'write_nb', 'new_nb', 'mk_cell', 'validate_nb', 'validate_cell', 'repair_nb', 'repair_cell',
62
- 'view_cell', 'cell_insert_line', 'cell_str_replace', 'cell_strs_replace', 'cell_replace_lines', 'cell_del_lines', 'cell_ast_replace', 'Notebook', 'NbCell', 'find_cells', 'summary_nb']
63
-
64
- __pyskill_params__ = {'replace_params': ('start_line', 'end_line', 'n_matches', 're_filter', 'invert_filter', 'use_regex')}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes