-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: support CGI to allow passing query parameters to kernel
Co-authored-by: Maarten Breddels <[email protected]>
- Loading branch information
1 parent
bfa0e8b
commit 6dee2ed
Showing
4 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T12:06:29.243603Z", | ||
"start_time": "2020-08-18T12:06:29.240780Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from urllib.parse import parse_qs\n", | ||
"import IPython.display" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T12:06:29.250356Z", | ||
"start_time": "2020-08-18T12:06:29.246161Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"query_string = os.environ.get('QUERY_STRING', '')\n", | ||
"parameters = parse_qs(query_string)\n", | ||
"print(\"query string parameters:\", parameters)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T12:06:29.258506Z", | ||
"start_time": "2020-08-18T12:06:29.253815Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# parameters is a dict of lists\n", | ||
"username = parameters.get('username', ['Kim'])[0]\n", | ||
"print(f'Hi {username}')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T12:06:29.275717Z", | ||
"start_time": "2020-08-18T12:06:29.261315Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"server = os.environ.get('SERVER_NAME', 'localhost') \n", | ||
"url = \"http://\" + server\n", | ||
"\n", | ||
"port = os.environ.get('SERVER_PORT', '')\n", | ||
"if port:\n", | ||
" url += \":\" + port\n", | ||
"\n", | ||
"path = os.environ.get('SCRIPT_NAME', '')\n", | ||
"url += path\n", | ||
"\n", | ||
" \n", | ||
"IPython.display.HTML(data=f\"\"\"\n", | ||
"<a href=\"{url}?username=Riley\">Link to myself as user Riley</a>\n", | ||
"\"\"\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def notebook_cgi_path(base_url): | ||
return base_url + "voila/render/cgi.ipynb" | ||
|
||
|
||
@pytest.fixture | ||
def voila_args(notebook_directory, voila_args_extra): | ||
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra | ||
|
||
|
||
async def test_cgi_using_query_parameters(capsys, http_server_client, notebook_cgi_path): | ||
response = await http_server_client.fetch(notebook_cgi_path + '?username=VOILA') | ||
assert response.code == 200 | ||
assert 'VOILA' in response.body.decode('utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T11:55:18.544213Z", | ||
"start_time": "2020-08-18T11:55:18.541029Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from urllib.parse import parse_qs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2020-08-18T11:55:19.281230Z", | ||
"start_time": "2020-08-18T11:55:19.278088Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"query_string = os.environ.get('QUERY_STRING', '')\n", | ||
"parameters = parse_qs(query_string)\n", | ||
"print(\"query string parameters:\", parameters)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters