-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing request URI to kernel env #414
Merged
SylvainCorlay
merged 1 commit into
voila-dashboards:master
from
derek-pyne:passing_request_uri
Aug 18, 2020
+195
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these environment variables be namespaced (prefixed with
VOILA
for example).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it follows https://tools.ietf.org/html/rfc3875
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok then...