|
131 | 131 | { |
132 | 132 | "data": { |
133 | 133 | "text/plain": [ |
134 | | - "datetime.datetime(2025, 10, 27, 14, 0)" |
| 134 | + "datetime.datetime(2025, 11, 6, 14, 0)" |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | "execution_count": null, |
|
645 | 645 | "id": "4b36f60b", |
646 | 646 | "metadata": {}, |
647 | 647 | "outputs": [ |
| 648 | + { |
| 649 | + "name": "stderr", |
| 650 | + "output_type": "stream", |
| 651 | + "text": [ |
| 652 | + "/var/folders/mp/wqhpw2456_79dcf12s7696m80000gn/T/ipykernel_76187/1644855005.py:8: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead\n", |
| 653 | + " if ctor: return await ctor(data, req) if asyncio.iscoroutinefunction(ctor) else ctor(data, req)\n" |
| 654 | + ] |
| 655 | + }, |
648 | 656 | { |
649 | 657 | "data": { |
650 | 658 | "text/plain": [ |
|
1366 | 1374 | " if cls in (Any,FT): cls=empty\n", |
1367 | 1375 | " if isinstance(resp, FileResponse) and not os.path.exists(resp.path): raise HTTPException(404, resp.path)\n", |
1368 | 1376 | " resp,kw = _part_resp(req, resp)\n", |
1369 | | - " if cls is not empty: return cls(resp, status_code=status_code, **kw)\n", |
1370 | 1377 | " if isinstance(resp, Response): return resp\n", |
| 1378 | + " if cls is not empty: return cls(resp, status_code=status_code, **kw)\n", |
1371 | 1379 | " if _is_ft_resp(resp):\n", |
1372 | 1380 | " cts = _xt_cts(req, resp)\n", |
1373 | 1381 | " return HTMLResponse(cts, status_code=status_code, **kw)\n", |
|
1379 | 1387 | " return cls(resp, status_code=status_code, **kw)" |
1380 | 1388 | ] |
1381 | 1389 | }, |
| 1390 | + { |
| 1391 | + "cell_type": "code", |
| 1392 | + "execution_count": null, |
| 1393 | + "id": "e2e4a9c2", |
| 1394 | + "metadata": {}, |
| 1395 | + "outputs": [], |
| 1396 | + "source": [ |
| 1397 | + "# Test for StreamingResponse behavior\n", |
| 1398 | + "# Before the fix, the following error occurs:\n", |
| 1399 | + "# TypeError: 'StreamingResponse' object is not iterable\n", |
| 1400 | + "import asyncio\n", |
| 1401 | + "from fasthtml.common import fast_app\n", |
| 1402 | + "from starlette.applications import Starlette\n", |
| 1403 | + "from starlette.responses import StreamingResponse\n", |
| 1404 | + "from starlette.testclient import TestClient\n", |
| 1405 | + "from starlette.routing import Route\n", |
| 1406 | + "\n", |
| 1407 | + "def simple_message_generator():\n", |
| 1408 | + " async def gen():\n", |
| 1409 | + " for i in range(3):\n", |
| 1410 | + " yield f\"data: message {i}\\n\\n\"\n", |
| 1411 | + " await asyncio.sleep(0.01)\n", |
| 1412 | + " return gen()\n", |
| 1413 | + "\n", |
| 1414 | + "app, rt = fast_app()\n", |
| 1415 | + "\n", |
| 1416 | + "@rt(\"/sse/notify\", methods=[\"GET\"])\n", |
| 1417 | + "async def get_sse_notify(req) -> StreamingResponse:\n", |
| 1418 | + " return EventStream(simple_message_generator())\n", |
| 1419 | + "\n", |
| 1420 | + "client = TestClient(app)\n", |
| 1421 | + "response = client.get('/sse/notify')\n", |
| 1422 | + "\n", |
| 1423 | + "assert response.status_code == 200\n", |
| 1424 | + "assert response.headers['content-type'].startswith('text/event-stream')\n", |
| 1425 | + "assert \"message\" in response.text" |
| 1426 | + ] |
| 1427 | + }, |
1382 | 1428 | { |
1383 | 1429 | "cell_type": "code", |
1384 | 1430 | "execution_count": null, |
|
2888 | 2934 | "name": "stdout", |
2889 | 2935 | "output_type": "stream", |
2890 | 2936 | "text": [ |
2891 | | - "Set to 2025-10-27 07:27:07.025956\n" |
| 2937 | + "Set to 2025-11-06 21:42:16.392974\n" |
2892 | 2938 | ] |
2893 | 2939 | }, |
2894 | 2940 | { |
2895 | 2941 | "data": { |
2896 | 2942 | "text/plain": [ |
2897 | | - "'Session time: 2025-10-27 07:27:07.025956'" |
| 2943 | + "'Session time: 2025-11-06 21:42:16.392974'" |
2898 | 2944 | ] |
2899 | 2945 | }, |
2900 | 2946 | "execution_count": null, |
|
3511 | 3557 | { |
3512 | 3558 | "data": { |
3513 | 3559 | "text/plain": [ |
3514 | | - "'Cookie was set at time 07:28:31.264910'" |
| 3560 | + "'Cookie was set at time 21:42:17.129483'" |
3515 | 3561 | ] |
3516 | 3562 | }, |
3517 | 3563 | "execution_count": null, |
|
0 commit comments