-
Notifications
You must be signed in to change notification settings - Fork 199
Add environment variable OSC_HTTP_MANUAL_APPROVE #2007
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
base: master
Are you sure you want to change the base?
Conversation
| http.client.print(40 * '-') | ||
| http.client.print(method, url) | ||
|
|
||
| if method != "GET" and os.environ['OSC_HTTP_MANUAL_APPROVE']: |
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.
os.environ['OSC_HTTP_MANUAL_APPROVE'] may raise KeyError.
| http.client.print(method, url) | ||
|
|
||
| if method != "GET" and os.environ['OSC_HTTP_MANUAL_APPROVE']: | ||
| print("osc is going to send "+ method +" request to " + urlopen_url) |
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.
Could you use a f-string instead?
Maybe drop this print and rely on the prompt below?
| if method != "GET" and os.environ['OSC_HTTP_MANUAL_APPROVE']: | ||
| print("osc is going to send "+ method +" request to " + urlopen_url) | ||
| if data: | ||
| print(data.decode("utf-8")) |
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.
This may fail. It is not guaranteed that the data is utf-8 text.
| y = input("press 'y' to continue or any other key to cancel") | ||
| if y != 'y' and y != 'Y': | ||
| raise Exception("Manual abort") | ||
|
|
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.
We should use functions and exceptions osc already offers:
(please excuse the wrong indendation, I've copied the code from a different place and slightly modified it to fit the scenario)
from .output import get_user_input
reply = get_user_input(
f"Do you want to make '{method}' request to '{urlopen_url}'?",
answers={"y": "yes", "n": "no"},
default_answer="n",
)
if reply == "n":
raise oscerr.UserAbort()
No description provided.