fastcore 2.2.25__tar.gz → 2.2.26__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.
- {fastcore-2.2.25/fastcore.egg-info → fastcore-2.2.26}/PKG-INFO +1 -1
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/__init__.py +1 -1
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/_modidx.py +3 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/xml.py +21 -9
- {fastcore-2.2.25 → fastcore-2.2.26/fastcore.egg-info}/PKG-INFO +1 -1
- {fastcore-2.2.25 → fastcore-2.2.26}/CONTRIBUTING.md +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/LICENSE +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/README.md +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/aio.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/all.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/ansi.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/apisurface.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/basics.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/dispatch.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/docments.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/docscrape.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/editskill.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/foundation.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/funccall.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/imghdr.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/imports.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/meta.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/nb_imports.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/nbio.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/net.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/parallel.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/py2pyi.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/script.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/shutil.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/style.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/test.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/tools.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/transform.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/utils.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/xdg.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore/xtras.py +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore.egg-info/SOURCES.txt +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore.egg-info/dependency_links.txt +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore.egg-info/entry_points.txt +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore.egg-info/requires.txt +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/fastcore.egg-info/top_level.txt +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/pyproject.toml +0 -0
- {fastcore-2.2.25 → fastcore-2.2.26}/setup.cfg +0 -0
|
@@ -817,6 +817,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
817
817
|
'fastcore.xml.E.__getattr__': ('xml.html#e.__getattr__', 'fastcore/xml.py'),
|
|
818
818
|
'fastcore.xml.E.__init__': ('xml.html#e.__init__', 'fastcore/xml.py'),
|
|
819
819
|
'fastcore.xml.E._namespace': ('xml.html#e._namespace', 'fastcore/xml.py'),
|
|
820
|
+
'fastcore.xml.E.attr_value': ('xml.html#e.attr_value', 'fastcore/xml.py'),
|
|
820
821
|
'fastcore.xml.FT': ('xml.html#ft', 'fastcore/xml.py'),
|
|
821
822
|
'fastcore.xml.FT.__call__': ('xml.html#ft.__call__', 'fastcore/xml.py'),
|
|
822
823
|
'fastcore.xml.FT.__eq__': ('xml.html#ft.__eq__', 'fastcore/xml.py'),
|
|
@@ -841,11 +842,13 @@ d = { 'settings': { 'branch': 'main',
|
|
|
841
842
|
'fastcore.xml.XML': ('xml.html#xml', 'fastcore/xml.py'),
|
|
842
843
|
'fastcore.xml.XML.__call__': ('xml.html#xml.__call__', 'fastcore/xml.py'),
|
|
843
844
|
'fastcore.xml.XML.__init__': ('xml.html#xml.__init__', 'fastcore/xml.py'),
|
|
845
|
+
'fastcore.xml.XML.__repr__': ('xml.html#xml.__repr__', 'fastcore/xml.py'),
|
|
844
846
|
'fastcore.xml.XML.__str__': ('xml.html#xml.__str__', 'fastcore/xml.py'),
|
|
845
847
|
'fastcore.xml.XML._child': ('xml.html#xml._child', 'fastcore/xml.py'),
|
|
846
848
|
'fastcore.xml.XML._render': ('xml.html#xml._render', 'fastcore/xml.py'),
|
|
847
849
|
'fastcore.xml.XML._repr_markdown_': ('xml.html#xml._repr_markdown_', 'fastcore/xml.py'),
|
|
848
850
|
'fastcore.xml.XML.bytes': ('xml.html#xml.bytes', 'fastcore/xml.py'),
|
|
851
|
+
'fastcore.xml.XML.render': ('xml.html#xml.render', 'fastcore/xml.py'),
|
|
849
852
|
'fastcore.xml._attr2tag': ('xml.html#_attr2tag', 'fastcore/xml.py'),
|
|
850
853
|
'fastcore.xml._escape': ('xml.html#_escape', 'fastcore/xml.py'),
|
|
851
854
|
'fastcore.xml._fix_k': ('xml.html#_fix_k', 'fastcore/xml.py'),
|
|
@@ -8,7 +8,7 @@ test_eq(to_xml(t), '<div hx-get="/get">\n <p class="a">hi</p>\n</div>\n')
|
|
|
8
8
|
test_eq(to_xml(Div(id='x')('child')), '<div id="x">child</div>\n')
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`E(prefix='', attr_ns=None, ns=None)` creates a namespace-bound XML factory. `e = E('w', attr_ns='w', ns={'w': uri})` supports expressions such as `e.tcW(type='dxa', w=2400)`. Tags and attributes preserve case. `prefix__name` selects an attribute namespace; `attrs_` accepts literal names. Expressions compose with text and ordered collections, retain their namespace bindings, and serialize as UTF-8 with `.bytes()`. XML text is escaped and booleans become `true`/`false
|
|
11
|
+
`E(prefix='', attr_ns=None, ns=None)` creates a namespace-bound XML factory. `e = E('w', attr_ns='w', ns={'w': uri})` supports expressions such as `e.tcW(type='dxa', w=2400)`. Tags and attributes preserve case. `prefix__name` selects an attribute namespace; `attrs_` accepts literal names. Expressions compose with text and ordered collections, retain their namespace bindings, and serialize as UTF-8 with `.bytes()`. XML text is escaped and booleans become `true`/`false`; subclasses override `attr_value` for vocabularies with other rules. The existing `ft` and `to_xml` APIs keep their HTML behavior.
|
|
12
12
|
|
|
13
13
|
Docs: https://fastcore.fast.ai/xml.html.md"""
|
|
14
14
|
|
|
@@ -341,7 +341,7 @@ def _render(self:XML, inherited, output):
|
|
|
341
341
|
if inherited.get(prefix) != uri:
|
|
342
342
|
name = f'xmlns:{prefix}' if prefix else 'xmlns'
|
|
343
343
|
output.append(f' {name}={quoteattr(uri)}')
|
|
344
|
-
for name, value in self.attrs: output.append(f' {name}={quoteattr(value)}')
|
|
344
|
+
for name, value in self.attrs.items(): output.append(f' {name}={quoteattr(value)}')
|
|
345
345
|
if not self.children:
|
|
346
346
|
output.append('/>')
|
|
347
347
|
return
|
|
@@ -353,22 +353,29 @@ def _render(self:XML, inherited, output):
|
|
|
353
353
|
output.append(f'</{self.tag}>')
|
|
354
354
|
|
|
355
355
|
@patch
|
|
356
|
-
def
|
|
356
|
+
def render(self:XML, inherited=None):
|
|
357
|
+
"Serialize, declaring the bindings not already in scope: `inherited` maps the prefixes bound where the markup will be inserted, `{}` declares every binding, and `None` renders a standalone document"
|
|
357
358
|
output = []
|
|
358
|
-
self._render({'xml': _xml_uri}, output)
|
|
359
|
+
self._render({'xml': _xml_uri, **({'': ''} if inherited is None else inherited)}, output)
|
|
359
360
|
return ''.join(output)
|
|
360
361
|
|
|
362
|
+
@patch
|
|
363
|
+
def __str__(self:XML): return self.render()
|
|
364
|
+
|
|
361
365
|
@patch
|
|
362
366
|
def bytes(self:XML):
|
|
363
367
|
"Serialize as UTF-8, without formatting whitespace."
|
|
364
|
-
return
|
|
368
|
+
return self.render().encode('utf-8')
|
|
365
369
|
|
|
366
370
|
@patch
|
|
367
371
|
def _repr_markdown_(self:XML): return f'```xml\n{self}\n```'
|
|
368
372
|
|
|
373
|
+
@patch
|
|
374
|
+
def __repr__(self:XML): return str(self)
|
|
375
|
+
|
|
369
376
|
# %% ../nbs/09_xml.ipynb #335a7366
|
|
370
377
|
class E:
|
|
371
|
-
"Create a namespace-bound XML factory."
|
|
378
|
+
"Create a namespace-bound XML factory: `e.tag(...)` and `e('tag', ...)` build detached expressions"
|
|
372
379
|
_node_cls = XML
|
|
373
380
|
|
|
374
381
|
def __init__(
|
|
@@ -395,12 +402,17 @@ class E:
|
|
|
395
402
|
if name.startswith('_'): raise AttributeError(name)
|
|
396
403
|
if name.endswith('_') and iskeyword(name[:-1]): name = name[:-1]
|
|
397
404
|
return partial(self, name)
|
|
405
|
+
def attr_value(self, tag, name, value):
|
|
406
|
+
"Serialize attribute `value` of `name` on `tag`; override to apply vocabulary rules such as `on`/`off`"
|
|
407
|
+
return _xml_value(value)
|
|
408
|
+
|
|
398
409
|
|
|
399
410
|
def __call__(self, name, /, *children, attrs_=None, **attrs):
|
|
411
|
+
"Build `name` (qualified by `prefix` unless it already has one) with `children` and `attrs`; call this directly for a tag that is not a Python identifier, such as `e('custom-name')`"
|
|
400
412
|
tag = _xml_qualify(name, self._prefix)
|
|
401
413
|
pairs = [(_xml_qualify(_xml_keyword(k), self._attr_ns), v) for k,v in attrs.items()]
|
|
402
414
|
pairs += list((attrs_ or {}).items())
|
|
403
|
-
ns,seen,values = dict(self._ns),set(),
|
|
415
|
+
ns,seen,values = dict(self._ns),set(),{}
|
|
404
416
|
prefix, _ = _xml_name(tag)
|
|
405
417
|
if prefix: ns[prefix] = self._namespace(prefix)
|
|
406
418
|
for key, value in pairs:
|
|
@@ -410,6 +422,6 @@ class E:
|
|
|
410
422
|
expanded = (ns[prefix] if prefix else '', local)
|
|
411
423
|
if expanded in seen: raise ValueError(f'Duplicate XML attribute: {key!r}')
|
|
412
424
|
seen.add(expanded)
|
|
413
|
-
values.
|
|
414
|
-
return self._node_cls(tag, children,
|
|
425
|
+
values[key] = self.attr_value(tag, key, value)
|
|
426
|
+
return self._node_cls(tag, children, values, ns)
|
|
415
427
|
|
|
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
|
|
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
|
|
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
|