-
Notifications
You must be signed in to change notification settings - Fork 505
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
Update blacklist
and whitelist
keywords
#1367
Changes from all commits
670cada
a9ab6f3
8d2e4ce
df02713
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ | |
############################################################################# | ||
|
||
import traitlets.config | ||
from traitlets import Bool, Dict, Enum, Int, List, Type, Unicode | ||
from traitlets import Bool, Dict, Enum, Int, List, Type, Unicode, validate | ||
|
||
from warnings import warn | ||
|
||
|
||
class VoilaConfiguration(traitlets.config.Configurable): | ||
|
@@ -52,30 +54,62 @@ class VoilaConfiguration(traitlets.config.Configurable): | |
) | ||
strip_sources = Bool(True, config=True, help="Strip sources from rendered html") | ||
|
||
file_whitelist = List( | ||
file_allowlist = List( | ||
Unicode(), | ||
[r".*\.(png|jpg|gif|svg)"], | ||
config=True, | ||
help=r""" | ||
List of regular expressions for controlling which static files are served. | ||
All files that are served should at least match 1 whitelist rule, and no blacklist rule | ||
Example: --VoilaConfiguration.file_whitelist="['.*\.(png|jpg|gif|svg)', 'public.*']" | ||
All files that are served should at least match 1 allowlist rule, and no denylist rule | ||
Example: --VoilaConfiguration.file_allowlist="['.*\.(png|jpg|gif|svg)', 'public.*']" | ||
""", | ||
) | ||
|
||
file_blacklist = List( | ||
file_whitelist = List( | ||
Unicode(), | ||
[r".*\.(png|jpg|gif|svg)"], | ||
config=True, | ||
help="""Deprecated, use `file_allowlist`""", | ||
) | ||
|
||
@validate("file_whitelist") | ||
def _valid_file_whitelist(self, proposal): | ||
warn( | ||
"Deprecated, use VoilaConfiguration.file_allowlist instead.", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return proposal["value"] | ||
Comment on lines
+68
to
+82
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. May I suggest another approach for this? @property
def file_whitelist(self):
warn(
"Deprecated, use VoilaConfiguration.file_allowlist instead.",
DeprecationWarning,
stacklevel=2,
)
return self.file_allowlist
@file_whitelist.setter
def file_whitelist(self, value):
warn(
"Deprecated, use VoilaConfiguration.file_allowlist instead.",
DeprecationWarning,
stacklevel=2,
)
self.file_allowlist = value That way we can get rid of the warnings.filterwarnings("default", category=DeprecationWarning, module="traitlets") ? 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. My suggestion applies if we consider going from a traitlet to a property is not backward incompatible 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. By doing so, users can not set the allow/deny list from the CLI or the 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. Good point 👍🏽 |
||
|
||
file_denylist = List( | ||
Unicode(), | ||
[r".*\.(ipynb|py)"], | ||
config=True, | ||
help=r""" | ||
List of regular expressions for controlling which static files are forbidden to be served. | ||
All files that are served should at least match 1 whitelist rule, and no blacklist rule | ||
Example: | ||
--VoilaConfiguration.file_whitelist="['.*']" # all files | ||
--VoilaConfiguration.file_blacklist="['private.*', '.*\.(ipynb)']" # except files in the private dir and notebook files | ||
List of regular expressions for controlling which static files are forbidden to be served. | ||
All files that are served should at least match 1 allowlist rule, and no denylist rule | ||
Example: | ||
--VoilaConfiguration.file_allowlist="['.*']" # all files | ||
--VoilaConfiguration.file_denylist="['private.*', '.*\.(ipynb)']" # except files in the private dir and notebook files | ||
""", | ||
) | ||
|
||
file_blacklist = List( | ||
Unicode(), | ||
[r".*\.(ipynb|py)"], | ||
config=True, | ||
help="""Deprecated, use `file_denylist`""", | ||
) | ||
|
||
@validate("file_blacklist") | ||
def _valid_file_blacklist(self, proposal): | ||
warn( | ||
"Deprecated, use VoilaConfiguration.file_denylist instead.", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return proposal["value"] | ||
|
||
language_kernel_mapping = Dict( | ||
{}, | ||
config=True, | ||
|
@@ -141,16 +175,16 @@ class VoilaConfiguration(traitlets.config.Configurable): | |
""", | ||
) | ||
|
||
extension_whitelist = List( | ||
extension_allowlist = List( | ||
None, | ||
allow_none=True, | ||
config=True, | ||
help="""The list of enabled JupyterLab extensions, if `None`, all extensions are loaded. | ||
This setting has higher priority than the `extension_blacklist` | ||
This setting has higher priority than the `extension_denylist` | ||
""", | ||
) | ||
|
||
extension_blacklist = List( | ||
extension_denylist = List( | ||
None, | ||
allow_none=True, | ||
config=True, | ||
|
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.
Mmmh, Maybe we should not do that and fix the deprecation warnings instead?
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.
Nope, the
DeprecationWarning
is hidden by default https://docs.python.org/3/library/exceptions.html#DeprecationWarning