Skip to content

Commit 750768f

Browse files
committed
fixes #586
1 parent bbcc9a1 commit 750768f

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
### New Features
144144

145145
- Add `process` param to `threaded` ([#550](https://github.com/fastai/fastcore/issues/550))
146-
- Check for `__xt__` in `to_xml`
146+
- Check for `__ft__` in `to_xml`
147147

148148

149149
## 1.5.34

fastcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.5.56"
1+
__version__ = "1.6.0"

fastcore/_modidx.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -560,22 +560,22 @@
560560
'fastcore.xdg.xdg_data_home': ('xdg.html#xdg_data_home', 'fastcore/xdg.py'),
561561
'fastcore.xdg.xdg_runtime_dir': ('xdg.html#xdg_runtime_dir', 'fastcore/xdg.py'),
562562
'fastcore.xdg.xdg_state_home': ('xdg.html#xdg_state_home', 'fastcore/xdg.py')},
563-
'fastcore.xml': { 'fastcore.xml.Html': ('xml.html#html', 'fastcore/xml.py'),
564-
'fastcore.xml.XT': ('xml.html#xt', 'fastcore/xml.py'),
565-
'fastcore.xml.XT.__getattr__': ('xml.html#xt.__getattr__', 'fastcore/xml.py'),
566-
'fastcore.xml.XT.__init__': ('xml.html#xt.__init__', 'fastcore/xml.py'),
567-
'fastcore.xml.XT.__setattr__': ('xml.html#xt.__setattr__', 'fastcore/xml.py'),
568-
'fastcore.xml.XT.attrs': ('xml.html#xt.attrs', 'fastcore/xml.py'),
569-
'fastcore.xml.XT.children': ('xml.html#xt.children', 'fastcore/xml.py'),
570-
'fastcore.xml.XT.tag': ('xml.html#xt.tag', 'fastcore/xml.py'),
563+
'fastcore.xml': { 'fastcore.xml.FT': ('xml.html#ft', 'fastcore/xml.py'),
564+
'fastcore.xml.FT.__getattr__': ('xml.html#ft.__getattr__', 'fastcore/xml.py'),
565+
'fastcore.xml.FT.__init__': ('xml.html#ft.__init__', 'fastcore/xml.py'),
566+
'fastcore.xml.FT.__setattr__': ('xml.html#ft.__setattr__', 'fastcore/xml.py'),
567+
'fastcore.xml.FT.attrs': ('xml.html#ft.attrs', 'fastcore/xml.py'),
568+
'fastcore.xml.FT.children': ('xml.html#ft.children', 'fastcore/xml.py'),
569+
'fastcore.xml.FT.tag': ('xml.html#ft.tag', 'fastcore/xml.py'),
570+
'fastcore.xml.Html': ('xml.html#html', 'fastcore/xml.py'),
571571
'fastcore.xml.__getattr__': ('xml.html#__getattr__', 'fastcore/xml.py'),
572572
'fastcore.xml._attrmap': ('xml.html#_attrmap', 'fastcore/xml.py'),
573573
'fastcore.xml._escape': ('xml.html#_escape', 'fastcore/xml.py'),
574574
'fastcore.xml._to_attr': ('xml.html#_to_attr', 'fastcore/xml.py'),
575+
'fastcore.xml.ft': ('xml.html#ft', 'fastcore/xml.py'),
575576
'fastcore.xml.highlight': ('xml.html#highlight', 'fastcore/xml.py'),
576577
'fastcore.xml.showtags': ('xml.html#showtags', 'fastcore/xml.py'),
577-
'fastcore.xml.to_xml': ('xml.html#to_xml', 'fastcore/xml.py'),
578-
'fastcore.xml.xt': ('xml.html#xt', 'fastcore/xml.py')},
578+
'fastcore.xml.to_xml': ('xml.html#to_xml', 'fastcore/xml.py')},
579579
'fastcore.xtras': { 'fastcore.xtras.ContextManagers': ('xtras.html#contextmanagers', 'fastcore/xtras.py'),
580580
'fastcore.xtras.ContextManagers.__enter__': ('xtras.html#contextmanagers.__enter__', 'fastcore/xtras.py'),
581581
'fastcore.xtras.ContextManagers.__exit__': ('xtras.html#contextmanagers.__exit__', 'fastcore/xtras.py'),

fastcore/xml.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_xml.ipynb.
22

33
# %% auto 0
4-
__all__ = ['XT', 'xt', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code',
4+
__all__ = ['FT', 'ft', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code',
55
'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U', 'S', 'Strike', 'Sub',
66
'Sup', 'Hr', 'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot',
77
'Tr', 'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea', 'Button', 'Select', 'Option',
@@ -26,7 +26,8 @@ def _attrmap(o):
2626
return o.lstrip('_').replace('_', '-')
2727

2828
# %% ../nbs/11_xml.ipynb
29-
class XT(list):
29+
class FT(list):
30+
"A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`"
3031
def __init__(self, tag, cs, attrs=None, void_=False, **kwargs):
3132
super().__init__([tag, cs, {**(attrs or {}), **kwargs}])
3233
self.void_ = void_
@@ -47,11 +48,11 @@ def __getattr__(self, k):
4748
return self.attrs[k.lstrip('_').replace('_', '-')]
4849

4950
# %% ../nbs/11_xml.ipynb
50-
def xt(tag:str, *c, void_=False, **kw):
51-
"Create an XML tag structure `[tag,children,attrs]` for `toxml()`"
51+
def ft(tag:str, *c, void_=False, **kw):
52+
"Create an `FT` structure for `to_xml()`"
5253
if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0])
5354
kw = {_attrmap(k):v for k,v in kw.items() if v is not None}
54-
return XT(tag.lower(),c,kw, void_=void_)
55+
return FT(tag.lower(),c,kw, void_=void_)
5556

5657
# %% ../nbs/11_xml.ipynb
5758
_g = globals()
@@ -65,14 +66,14 @@ def xt(tag:str, *c, void_=False, **kw):
6566
'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',
6667
'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']
6768

68-
for o in _all_: _g[o] = partial(xt, o.lower())
69+
for o in _all_: _g[o] = partial(ft, o.lower())
6970

7071
# %% ../nbs/11_xml.ipynb
71-
def Html(*c, doctype=True, **kwargs)->XT:
72+
def Html(*c, doctype=True, **kwargs)->FT:
7273
"An HTML tag, optionally preceeded by `!DOCTYPE HTML`"
73-
res = xt('html', *c, **kwargs)
74+
res = ft('html', *c, **kwargs)
7475
if not doctype: return res
75-
return (xt('!DOCTYPE', html=True, void_=True), res)
76+
return (ft('!DOCTYPE', html=True, void_=True), res)
7677

7778
# %% ../nbs/11_xml.ipynb
7879
def _escape(s): return '' if s is None else escape(s) if isinstance(s, str) else s
@@ -91,10 +92,10 @@ def _to_attr(k,v):
9192

9293
# %% ../nbs/11_xml.ipynb
9394
def to_xml(elm, lvl=0):
94-
"Convert `xt` element tree into an XML string"
95+
"Convert `ft` element tree into an XML string"
9596
if elm is None: return ''
9697
if isinstance(elm, tuple): return '\n'.join(to_xml(o) for o in elm)
97-
if hasattr(elm, '__xt__'): elm = elm.__xt__()
98+
if hasattr(elm, '__ft__'): elm = elm.__ft__()
9899
sp = ' ' * lvl
99100
if not isinstance(elm, list): return f'{_escape(elm)}\n'
100101

@@ -107,7 +108,7 @@ def to_xml(elm, lvl=0):
107108
isvoid = getattr(elm, 'void_', False)
108109
cltag = '' if isvoid else f'</{tag}>'
109110
if not cs: return f'{sp}<{stag}>{cltag}\n'
110-
if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__xt__'):
111+
if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__ft__'):
111112
return f'{sp}<{stag}>{_escape(cs[0])}{cltag}\n'
112113
res = f'{sp}<{stag}>\n'
113114
res += ''.join(to_xml(c, lvl=lvl+2) for c in cs)
@@ -125,10 +126,10 @@ def showtags(s):
125126
{escape(to_xml(s))}
126127
</code></pre>"""
127128

128-
XT._repr_markdown_ = highlight
129+
FT._repr_markdown_ = highlight
129130

130131
# %% ../nbs/11_xml.ipynb
131132
def __getattr__(tag):
132133
if tag.startswith('_') or tag[0].islower(): raise AttributeError
133-
def _f(*c, target_id=None, **kwargs): return xt(tag, *c, target_id=target_id, **kwargs)
134+
def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs)
134135
return _f

nbs/11_xml.ipynb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"outputs": [],
7272
"source": [
7373
"#|export\n",
74-
"class XT(list):\n",
74+
"class FT(list):\n",
75+
" \"A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`\"\n",
7576
" def __init__(self, tag, cs, attrs=None, void_=False, **kwargs):\n",
7677
" super().__init__([tag, cs, {**(attrs or {}), **kwargs}])\n",
7778
" self.void_ = void_\n",
@@ -100,11 +101,11 @@
100101
"outputs": [],
101102
"source": [
102103
"#| export\n",
103-
"def xt(tag:str, *c, void_=False, **kw):\n",
104-
" \"Create an XML tag structure `[tag,children,attrs]` for `toxml()`\"\n",
104+
"def ft(tag:str, *c, void_=False, **kw):\n",
105+
" \"Create an `FT` structure for `to_xml()`\"\n",
105106
" if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0])\n",
106107
" kw = {_attrmap(k):v for k,v in kw.items() if v is not None}\n",
107-
" return XT(tag.lower(),c,kw, void_=void_)"
108+
" return FT(tag.lower(),c,kw, void_=void_)"
108109
]
109110
},
110111
{
@@ -126,15 +127,15 @@
126127
" 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',\n",
127128
" 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']\n",
128129
"\n",
129-
"for o in _all_: _g[o] = partial(xt, o.lower())"
130+
"for o in _all_: _g[o] = partial(ft, o.lower())"
130131
]
131132
},
132133
{
133134
"cell_type": "markdown",
134135
"id": "732e44ab",
135136
"metadata": {},
136137
"source": [
137-
"The main HTML tags are exported as `xt` partials.\n",
138+
"The main HTML tags are exported as `ft` partials.\n",
138139
"\n",
139140
"Attributes are passed as keywords. Use 'klass' and 'fr' instead of 'class' and 'for', to avoid Python reserved word clashes."
140141
]
@@ -147,11 +148,11 @@
147148
"outputs": [],
148149
"source": [
149150
"#| export\n",
150-
"def Html(*c, doctype=True, **kwargs)->XT:\n",
151+
"def Html(*c, doctype=True, **kwargs)->FT:\n",
151152
" \"An HTML tag, optionally preceeded by `!DOCTYPE HTML`\"\n",
152-
" res = xt('html', *c, **kwargs)\n",
153+
" res = ft('html', *c, **kwargs)\n",
153154
" if not doctype: return res\n",
154-
" return (xt('!DOCTYPE', html=True, void_=True), res)"
155+
" return (ft('!DOCTYPE', html=True, void_=True), res)"
155156
]
156157
},
157158
{
@@ -295,10 +296,10 @@
295296
"source": [
296297
"#| export\n",
297298
"def to_xml(elm, lvl=0):\n",
298-
" \"Convert `xt` element tree into an XML string\"\n",
299+
" \"Convert `ft` element tree into an XML string\"\n",
299300
" if elm is None: return ''\n",
300301
" if isinstance(elm, tuple): return '\\n'.join(to_xml(o) for o in elm)\n",
301-
" if hasattr(elm, '__xt__'): elm = elm.__xt__()\n",
302+
" if hasattr(elm, '__ft__'): elm = elm.__ft__()\n",
302303
" sp = ' ' * lvl\n",
303304
" if not isinstance(elm, list): return f'{_escape(elm)}\\n'\n",
304305
"\n",
@@ -311,7 +312,7 @@
311312
" isvoid = getattr(elm, 'void_', False)\n",
312313
" cltag = '' if isvoid else f'</{tag}>'\n",
313314
" if not cs: return f'{sp}<{stag}>{cltag}\\n'\n",
314-
" if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__xt__'):\n",
315+
" if len(cs)==1 and not isinstance(cs[0],(list,tuple)) and not hasattr(cs[0],'__ft__'):\n",
315316
" return f'{sp}<{stag}>{_escape(cs[0])}{cltag}\\n'\n",
316317
" res = f'{sp}<{stag}>\\n'\n",
317318
" res += ''.join(to_xml(c, lvl=lvl+2) for c in cs)\n",
@@ -378,7 +379,7 @@
378379
"{escape(to_xml(s))}\n",
379380
"</code></pre>\"\"\"\n",
380381
"\n",
381-
"XT._repr_markdown_ = highlight"
382+
"FT._repr_markdown_ = highlight"
382383
]
383384
},
384385
{
@@ -391,7 +392,7 @@
391392
"#| export\n",
392393
"def __getattr__(tag):\n",
393394
" if tag.startswith('_') or tag[0].islower(): raise AttributeError\n",
394-
" def _f(*c, target_id=None, **kwargs): return xt(tag, *c, target_id=target_id, **kwargs)\n",
395+
" def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs)\n",
395396
" return _f"
396397
]
397398
},

settings.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ author = Jeremy Howard and Sylvain Gugger
88
author_email = infos@fast.ai
99
copyright = fast.ai
1010
branch = master
11-
version = 1.5.56
12-
min_python = 3.7
11+
version = 1.6.0
12+
min_python = 3.8
1313
audience = Developers
1414
language = English
1515
custom_sidebar = False
1616
license = apache2
17-
status = 4
17+
status = 5
1818
nbs_path = nbs
1919
doc_path = _docs
2020
dev_requirements = numpy nbdev>=0.2.39 matplotlib pillow torch pandas nbclassic

0 commit comments

Comments
 (0)