|
129 | 129 | { |
130 | 130 | "data": { |
131 | 131 | "text/plain": [ |
132 | | - "datetime.datetime(2024, 9, 17, 14, 0)" |
| 132 | + "datetime.datetime(2024, 9, 19, 14, 0)" |
133 | 133 | ] |
134 | 134 | }, |
135 | 135 | "execution_count": null, |
|
588 | 588 | { |
589 | 589 | "cell_type": "code", |
590 | 590 | "execution_count": null, |
591 | | - "id": "0b6ac588", |
| 591 | + "id": "33d3bc16", |
592 | 592 | "metadata": {}, |
593 | 593 | "outputs": [], |
594 | 594 | "source": [ |
|
599 | 599 | " d = _annotations(anno)\n", |
600 | 600 | " if req.headers.get('content-type', None)=='application/json': data = await req.json()\n", |
601 | 601 | " else: data = form2dict(await parse_form(req))\n", |
| 602 | + " if req.query_params: data = {**data, **dict(req.query_params)}\n", |
602 | 603 | " cargs = {k: _form_arg(k, v, d) for k, v in data.items() if not d or k in d}\n", |
603 | 604 | " return anno(**cargs)" |
604 | 605 | ] |
|
734 | 735 | "print(response.text)" |
735 | 736 | ] |
736 | 737 | }, |
| 738 | + { |
| 739 | + "cell_type": "code", |
| 740 | + "execution_count": null, |
| 741 | + "id": "a3ded5ec", |
| 742 | + "metadata": {}, |
| 743 | + "outputs": [ |
| 744 | + { |
| 745 | + "name": "stdout", |
| 746 | + "output_type": "stream", |
| 747 | + "text": [ |
| 748 | + "[<starlette.requests.Request object>, <starlette.applications.Starlette object>, '1', HttpHeader(k='value1', v='value3')]\n" |
| 749 | + ] |
| 750 | + } |
| 751 | + ], |
| 752 | + "source": [ |
| 753 | + "def g(req, this:Starlette, a:str, b:HttpHeader): ...\n", |
| 754 | + "\n", |
| 755 | + "async def f(req):\n", |
| 756 | + " a = await _wrap_req(req, _sig(g).parameters)\n", |
| 757 | + " return Response(str(a))\n", |
| 758 | + "\n", |
| 759 | + "app = Starlette(routes=[Route('/', f, methods=['POST'])])\n", |
| 760 | + "client = TestClient(app)\n", |
| 761 | + "\n", |
| 762 | + "response = client.post('/?a=1', data=d)\n", |
| 763 | + "print(response.text)" |
| 764 | + ] |
| 765 | + }, |
737 | 766 | { |
738 | 767 | "cell_type": "code", |
739 | 768 | "execution_count": null, |
|
2084 | 2113 | " a:int|None; b:str\n", |
2085 | 2114 | " def __init__(self, a, b='foo'): store_attr()\n", |
2086 | 2115 | "\n", |
2087 | | - "@app.post(\"/bodie2/\")\n", |
| 2116 | + "@rt(\"/bodie2/\", methods=['get','post'])\n", |
2088 | 2117 | "def bodie(d:Bodie2): return f\"a: {d.a}; b: {d.b}\"" |
2089 | 2118 | ] |
2090 | 2119 | }, |
|
2101 | 2130 | { |
2102 | 2131 | "cell_type": "code", |
2103 | 2132 | "execution_count": null, |
2104 | | - "id": "6c1fbc4b", |
| 2133 | + "id": "48f0a45e", |
| 2134 | + "metadata": {}, |
| 2135 | + "outputs": [], |
| 2136 | + "source": [ |
| 2137 | + "d = dict(a=1, b='foo')\n", |
| 2138 | + "\n", |
| 2139 | + "test_r(cli, '/bodie/me', '{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}', 'post', data=dict(a=1, b='foo', nm='me'))\n", |
| 2140 | + "test_r(cli, '/bodied/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n", |
| 2141 | + "test_r(cli, '/bodie2/', 'a: 1; b: foo', 'post', data={'a':1})\n", |
| 2142 | + "test_r(cli, '/bodie2/?a=1&b=foo&nm=me', 'a: 1; b: foo')\n", |
| 2143 | + "test_r(cli, '/bodient/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n", |
| 2144 | + "test_r(cli, '/bodietd/', '{\"a\":1,\"b\":\"foo\"}', 'post', data=d)" |
| 2145 | + ] |
| 2146 | + }, |
| 2147 | + { |
| 2148 | + "cell_type": "code", |
| 2149 | + "execution_count": null, |
| 2150 | + "id": "73363a37", |
2105 | 2151 | "metadata": {}, |
2106 | 2152 | "outputs": [], |
2107 | 2153 | "source": [ |
|
2117 | 2163 | { |
2118 | 2164 | "cell_type": "code", |
2119 | 2165 | "execution_count": null, |
2120 | | - "id": "51cd4643", |
| 2166 | + "id": "0aeaac36", |
2121 | 2167 | "metadata": {}, |
2122 | 2168 | "outputs": [], |
2123 | 2169 | "source": [ |
|
2129 | 2175 | "test_eq(response, '{\"b\": \"Lorem\", \"a\": 15}')" |
2130 | 2176 | ] |
2131 | 2177 | }, |
2132 | | - { |
2133 | | - "cell_type": "code", |
2134 | | - "execution_count": null, |
2135 | | - "id": "48f0a45e", |
2136 | | - "metadata": {}, |
2137 | | - "outputs": [], |
2138 | | - "source": [ |
2139 | | - "d = dict(a=1, b='foo')\n", |
2140 | | - "\n", |
2141 | | - "test_r(cli, '/bodie/me', '{\"a\":1,\"b\":\"foo\",\"nm\":\"me\"}', 'post', data=dict(a=1, b='foo', nm='me'))\n", |
2142 | | - "test_r(cli, '/bodied/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n", |
2143 | | - "test_r(cli, '/bodie2/', 'a: 1; b: foo', 'post', data={'a':1})\n", |
2144 | | - "test_r(cli, '/bodient/', '{\"a\":\"1\",\"b\":\"foo\"}', 'post', data=d)\n", |
2145 | | - "test_r(cli, '/bodietd/', '{\"a\":1,\"b\":\"foo\"}', 'post', data=d)" |
2146 | | - ] |
2147 | | - }, |
2148 | 2178 | { |
2149 | 2179 | "cell_type": "code", |
2150 | 2180 | "execution_count": null, |
|
2155 | 2185 | "name": "stdout", |
2156 | 2186 | "output_type": "stream", |
2157 | 2187 | "text": [ |
2158 | | - "Set to 2024-09-15 07:09:53.847227\n" |
| 2188 | + "Set to 2024-09-19 11:49:19.536169\n" |
2159 | 2189 | ] |
2160 | 2190 | }, |
2161 | 2191 | { |
2162 | 2192 | "data": { |
2163 | 2193 | "text/plain": [ |
2164 | | - "'Session time: 2024-09-15 07:09:53.847227'" |
| 2194 | + "'Session time: 2024-09-19 11:49:19.536169'" |
2165 | 2195 | ] |
2166 | 2196 | }, |
2167 | 2197 | "execution_count": null, |
|
2392 | 2422 | { |
2393 | 2423 | "data": { |
2394 | 2424 | "text/plain": [ |
2395 | | - "'Cookie was set at time 07:09:55.075607'" |
| 2425 | + "'Cookie was set at time 11:49:19.827380'" |
2396 | 2426 | ] |
2397 | 2427 | }, |
2398 | 2428 | "execution_count": null, |
|
0 commit comments