-
Notifications
You must be signed in to change notification settings - Fork 102
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
Expand the ruff config to include import sorting and others. #234
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5150c2d
Update and move ruff config to pyproject.toml
robhudson 6b8c68d
Bump pre-commit versions
robhudson d38dbeb
Run pyproject-fmt
robhudson 71afcf5
Run updated ruff config on all files
robhudson f977aee
Add comments after some testing
robhudson 58e9848
Add `.python-version` to gitignore for pyenv + tox
robhudson 5c3ad58
Add pyupgrade to ruff and fix errors
robhudson 1cbb2b7
Update CHANGELOG.md
robhudson 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.sw[po] | ||
.cache | ||
.coverage | ||
.python-version | ||
.tox | ||
dist | ||
build | ||
|
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
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
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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
from __future__ import annotations | ||
from typing import Dict, Literal, TYPE_CHECKING | ||
|
||
from typing import TYPE_CHECKING, Literal | ||
|
||
if TYPE_CHECKING: | ||
from django.http import HttpRequest | ||
|
||
|
||
def nonce(request: HttpRequest) -> Dict[Literal["CSP_NONCE"], str]: | ||
nonce = request.csp_nonce if hasattr(request, "csp_nonce") else "" | ||
def nonce(request: HttpRequest) -> dict[Literal["CSP_NONCE"], str]: | ||
nonce = getattr(request, "csp_nonce", "") | ||
|
||
return {"CSP_NONCE": nonce} |
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
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
import base64 | ||
import http.client as http_client | ||
import os | ||
|
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
from __future__ import annotations | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from django import template | ||
from django.template.base import token_kwargs | ||
|
||
from csp.utils import build_script_tag | ||
|
||
if TYPE_CHECKING: | ||
from django.template.base import NodeList, FilterExpression, Token, Parser | ||
from django.template.base import FilterExpression, NodeList, Parser, Token | ||
from django.template.context import Context | ||
|
||
register = template.Library() | ||
|
@@ -18,7 +20,7 @@ def _unquote(s: str) -> str: | |
|
||
|
||
@register.tag(name="script") | ||
def script(parser: Parser, token: Token) -> "NonceScriptNode": | ||
def script(parser: Parser, token: Token) -> NonceScriptNode: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
# Parse out any keyword args | ||
token_args = token.split_contents() | ||
kwargs = token_kwargs(token_args[1:], parser) | ||
|
@@ -36,7 +38,7 @@ def __init__(self, nodelist: NodeList, **kwargs: FilterExpression) -> None: | |
for k, v in kwargs.items(): | ||
self.script_attrs[k] = self._get_token_value(v) | ||
|
||
def _get_token_value(self, t: FilterExpression) -> Optional[str]: | ||
def _get_token_value(self, t: FilterExpression) -> str | None: | ||
if hasattr(t, "token") and t.token: | ||
return _unquote(t.token) | ||
return None | ||
|
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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from csp.constants import NONCE, SELF | ||
|
||
|
||
CONTENT_SECURITY_POLICY = { | ||
"DIRECTIVES": { | ||
"default-src": [SELF, NONCE], | ||
|
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
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
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
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
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
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
Oops, something went wrong.
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.
It's interesting that this is allowed with Python 3.8 with
from __future__ import annotations