Skip to content

Commit

Permalink
fixes #509
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Oct 9, 2024
1 parent 82ec504 commit d856beb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _fix_anno(t):
origin = get_origin(t)
if origin is Union or origin is UnionType or origin in (list,List):
t = first(o for o in get_args(t) if o!=type(None))
d = {bool: str2bool, int: str2int, date: str2date}
d = {bool: str2bool, int: str2int, date: str2date, UploadFile: noop}
res = d.get(t, t)
if origin in (list,List): return partial(_mk_list, res)
return lambda o: res(o[-1]) if isinstance(o,(list,tuple)) else res(o)
Expand Down
54 changes: 50 additions & 4 deletions nbs/api/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
{
"data": {
"text/plain": [
"datetime.datetime(2024, 9, 24, 14, 0)"
"datetime.datetime(2024, 10, 10, 14, 0)"
]
},
"execution_count": null,
Expand Down Expand Up @@ -363,7 +363,7 @@
" origin = get_origin(t)\n",
" if origin is Union or origin is UnionType or origin in (list,List):\n",
" t = first(o for o in get_args(t) if o!=type(None))\n",
" d = {bool: str2bool, int: str2int, date: str2date}\n",
" d = {bool: str2bool, int: str2int, date: str2date, UploadFile: noop}\n",
" res = d.get(t, t)\n",
" if origin in (list,List): return partial(_mk_list, res)\n",
" return lambda o: res(o[-1]) if isinstance(o,(list,tuple)) else res(o)"
Expand Down Expand Up @@ -1441,6 +1441,16 @@
" return f(path) if callable(path) else f"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a82b103f",
"metadata": {},
"outputs": [],
"source": [
"%ai reset"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -2196,6 +2206,42 @@
"test_eq(response, '{\"b\": \"Lorem\", \"a\": 15}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4034ee37",
"metadata": {},
"outputs": [],
"source": [
"files = [ ('files', ('file1.txt', b'content1')),\n",
" ('files', ('file2.txt', b'content2')) ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04881594",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"200\n",
"content1,content2\n"
]
}
],
"source": [
"@rt(\"/uploads\")\n",
"async def post(files:list[UploadFile]):\n",
" return ','.join([(await file.read()).decode() for file in files])\n",
"\n",
"res = cli.post('/uploads', files=files) \n",
"print(res.status_code)\n",
"print(res.text)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -2206,13 +2252,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Set to 2024-09-24 15:25:23.127900\n"
"Set to 2024-10-10 04:51:50.335203\n"
]
},
{
"data": {
"text/plain": [
"'Session time: 2024-09-24 15:25:23.127900'"
"'Session time: 2024-10-10 04:51:50.335203'"
]
},
"execution_count": null,
Expand Down

0 comments on commit d856beb

Please sign in to comment.