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