|
43 | 43 | "outputs": [], |
44 | 44 | "source": [ |
45 | 45 | "#| export\n", |
46 | | - "import json,uuid,inspect,types,signal,asyncio,threading,inspect\n", |
| 46 | + "import json,uuid,inspect,types,signal,asyncio,threading,inspect,random\n", |
47 | 47 | "\n", |
48 | 48 | "from fastcore.utils import *\n", |
49 | 49 | "from fastcore.xml import *\n", |
|
63 | 63 | "from dateutil import parser as dtparse\n", |
64 | 64 | "from httpx import ASGITransport, AsyncClient\n", |
65 | 65 | "from anyio import from_thread\n", |
66 | | - "from uuid import uuid4\n", |
| 66 | + "from uuid import uuid4, UUID\n", |
67 | 67 | "from base64 import b85encode,b64encode\n", |
68 | 68 | "\n", |
69 | 69 | "from fasthtml.starlette import *" |
|
131 | 131 | { |
132 | 132 | "data": { |
133 | 133 | "text/plain": [ |
134 | | - "datetime.datetime(2025, 5, 19, 14, 0)" |
| 134 | + "datetime.datetime(2025, 5, 29, 14, 0)" |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | "execution_count": null, |
|
754 | 754 | "name": "stdout", |
755 | 755 | "output_type": "stream", |
756 | 756 | "text": [ |
757 | | - "b'{}'\n", |
758 | 757 | "[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '']\n" |
759 | 758 | ] |
760 | 759 | } |
|
789 | 788 | "name": "stdout", |
790 | 789 | "output_type": "stream", |
791 | 790 | "text": [ |
792 | | - "b'{}'\n", |
793 | 791 | "Missing required field: a\n" |
794 | 792 | ] |
795 | 793 | } |
|
2615 | 2613 | "execution_count": null, |
2616 | 2614 | "id": "73363a37", |
2617 | 2615 | "metadata": {}, |
2618 | | - "outputs": [ |
2619 | | - { |
2620 | | - "name": "stdout", |
2621 | | - "output_type": "stream", |
2622 | | - "text": [ |
2623 | | - "b'{\"b\": \"Lorem\", \"a\": 15}'\n" |
2624 | | - ] |
2625 | | - } |
2626 | | - ], |
| 2616 | + "outputs": [], |
2627 | 2617 | "source": [ |
2628 | 2618 | "# Testing POST with Content-Type: application/json\n", |
2629 | 2619 | "@app.post(\"/\")\n", |
|
2716 | 2706 | "name": "stdout", |
2717 | 2707 | "output_type": "stream", |
2718 | 2708 | "text": [ |
2719 | | - "Set to 2025-05-19 11:46:01.972924\n" |
| 2709 | + "Set to 2025-05-29 08:31:48.235262\n" |
2720 | 2710 | ] |
2721 | 2711 | }, |
2722 | 2712 | { |
2723 | 2713 | "data": { |
2724 | 2714 | "text/plain": [ |
2725 | | - "'Session time: 2025-05-19 11:46:01.972924'" |
| 2715 | + "'Session time: 2025-05-29 08:31:48.235262'" |
2726 | 2716 | ] |
2727 | 2717 | }, |
2728 | 2718 | "execution_count": null, |
|
3241 | 3231 | " <html>\n", |
3242 | 3232 | " <head>\n", |
3243 | 3233 | " <title>FastHTML page</title>\n", |
| 3234 | + " <link rel=\"canonical\" href=\"http://testserver/setcookie\">\n", |
3244 | 3235 | " <meta charset=\"utf-8\">\n", |
3245 | 3236 | " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, viewport-fit=cover\">\n", |
3246 | 3237 | "<script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/htmx.min.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/[email protected]/fasthtml.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js\"></script><script src=\"https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js\"></script><script>\n", |
|
3260 | 3251 | { |
3261 | 3252 | "data": { |
3262 | 3253 | "text/plain": [ |
3263 | | - "'Cookie was set at time 11:46:35.877920'" |
| 3254 | + "'Cookie was set at time 08:31:49.013668'" |
3264 | 3255 | ] |
3265 | 3256 | }, |
3266 | 3257 | "execution_count": null, |
|
3592 | 3583 | "outputs": [], |
3593 | 3584 | "source": [ |
3594 | 3585 | "#| export\n", |
3595 | | - "def unqid():\n", |
3596 | | - " res = b64encode(uuid4().bytes)\n", |
| 3586 | + "def unqid(seeded=False):\n", |
| 3587 | + " id4 = UUID(int=random.getrandbits(128), version=4) if seeded else uuid4()\n", |
| 3588 | + " res = b64encode(id4.bytes)\n", |
3597 | 3589 | " return '_' + res.decode().rstrip('=').translate(str.maketrans('+/', '_-'))" |
3598 | 3590 | ] |
3599 | 3591 | }, |
|
0 commit comments