Skip to content
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

Added safe mode option and url builder #23

Merged
merged 7 commits into from
Aug 10, 2022
Merged

Added safe mode option and url builder #23

merged 7 commits into from
Aug 10, 2022

Conversation

te25son
Copy link
Owner

@te25son te25son commented Aug 8, 2022

closes #22

@te25son te25son self-assigned this Aug 8, 2022
None instead.
"""
return get_current_context(silent=True)
return context.obj.get("DEBUG") if (context := get_current_context(silent=True)) else False
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern of adding an object to the context and fetching it this way is repeated (and will be repeated again if the submit dry-run is ever fully implemented).

Maybe add a new util? JokesContext?

Copy link
Owner Author

@te25son te25son Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context can already be fetched from anywhere in the code via get_current_context.

We could add a method like this though:

def get_context_object(key: str, default: bool = False) -> bool:
    return c.obj.get(key) if (c := get_current_context(silent=True)) else default

SUBMIT = "submit"


def format_params(dict: Mapping[str, Primitive]) -> str:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing params here and then calling the dict() method internally is possible, but it doesn't ensure the safety of the join, specifically the f"{k}={v}" since the pydantic dict method only requires a dict[str, Any].

So theoretically we could construct a parameter class that returns a dict of type dict[str, SomeComplexType] which would either break the query string or return something illegible.

@te25son te25son merged commit 6d17a9d into main Aug 10, 2022
@te25son te25son deleted the safe-mode-option branch August 10, 2022 08:59
@te25son te25son mentioned this pull request Aug 10, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add safe mode to get request
1 participant