-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 135a066
Showing
11 changed files
with
165 additions
and
0 deletions.
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,41 @@ | ||
[flake8] | ||
# Show exactly where in a line the error happened | ||
#show-source = True | ||
|
||
max-line-length = 88 | ||
# Add _ as a builtin for localisation stuff | ||
|
||
# check syntax in doctests | ||
doctests = True | ||
max-complexity = 15 | ||
|
||
# Plugin configs | ||
# required plugins: | ||
|
||
# https://github.com/Melevir/flake8-cognitive-complexity | ||
# Provides cognitive complexity checking | ||
|
||
# https://github.com/adamchainz/flake8-comprehensions | ||
# Checks list/dict/set/* comprehensions for simplification or replacement | ||
|
||
# https://github.com/PyCQA/pep8-naming | ||
# checks names against PEP8 rules (eg CamelCase for class names) | ||
|
||
# https://github.com/best-doctor/flake8-annotations-coverage | ||
# Checks code for type annotations | ||
|
||
# https://pypi.org/project/flake8-isort/ | ||
# Ensures imports are well sorted | ||
|
||
# https://pypi.org/project/flake8-noqa/ | ||
# Ensures that noqa statements are correctly formed | ||
|
||
# https://github.com/MichaelKim0407/flake8-use-fstring | ||
# Prefers fstrings over .format and modulo based formatters | ||
|
||
max-cognitive-complexity = 15 | ||
|
||
# require that all noqa directves disable specific errors | ||
noqa-require-code = True | ||
|
||
docstring-convention = numpy |
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,4 @@ | ||
venv | ||
.mypy_cache | ||
.pytest_cache | ||
.vscode |
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,2 @@ | ||
[mypy] | ||
strict=True |
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,9 @@ | ||
[tool.isort] | ||
multi_line_output = 5 | ||
line_length = 88 | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = ["tests"] # Search for tests in tests/ | ||
|
||
[tool.coverage.run] | ||
omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories |
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,29 @@ | ||
attrs==21.4.0 | ||
cognitive-complexity==1.2.0 | ||
coverage==6.2 | ||
flake8==4.0.1 | ||
flake8-annotations-coverage==0.0.5 | ||
flake8-cognitive-complexity==0.1.0 | ||
flake8-docstrings==1.6.0 | ||
flake8-noqa==1.2.1 | ||
flake8-polyfill==1.0.2 | ||
flake8-use-fstring==1.3 | ||
iniconfig==1.1.1 | ||
isort==5.10.1 | ||
mccabe==0.6.1 | ||
mypy==0.931 | ||
mypy-extensions==0.4.3 | ||
packaging==21.3 | ||
pep8-naming==0.12.1 | ||
pluggy==1.0.0 | ||
py==1.11.0 | ||
pycodestyle==2.8.0 | ||
pydocstyle==6.1.1 | ||
pyflakes==2.4.0 | ||
pyparsing==3.0.6 | ||
pytest==6.2.5 | ||
pytest-cov==3.0.0 | ||
snowballstemmer==2.2.0 | ||
toml==0.10.2 | ||
tomli==2.0.0 | ||
typing_extensions==4.0.1 |
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 @@ | ||
irctokens==2.0.1 |
Empty file.
Empty file.
Empty file.
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,24 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
|
||
from irctokens.line import Line | ||
|
||
|
||
class BasePermissionHandler(abc.ABC): | ||
""" | ||
BasePermisionHandler covers everything required to manage permissions based | ||
on incoming information from an IRC message | ||
""" | ||
|
||
@abc.abstractmethod | ||
def check_permissions(self, line: Line) -> list[str]: | ||
""" | ||
Return the permissions available to the sender of a given line. | ||
Do NOT modify line. | ||
:param line: The line to check permissions on | ||
:return: Any and all permissions a user on a given line may have | ||
""" | ||
... |
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,55 @@ | ||
from __future__ import annotations | ||
|
||
from fnmatch import fnmatch | ||
|
||
from base import BasePermissionHandler | ||
from irctokens.line import Line | ||
|
||
# spell-checker: words oper | ||
|
||
|
||
class DefaultPermissionHandler(BasePermissionHandler): | ||
def __init__(self) -> None: | ||
self.mask_permissions: dict[str, list[str]] = {} | ||
self.enable_oper = True | ||
self.oper_permissions: dict[str, list[str]] = {} | ||
super().__init__() | ||
|
||
def check_masks(self, to_check: str) -> list[str]: | ||
out: list[str] = [] | ||
|
||
for mask in self.mask_permissions: | ||
if fnmatch(to_check, mask): | ||
out.extend(self.mask_permissions[mask]) | ||
|
||
return out | ||
|
||
def check_oper(self, oper_name: str) -> list[str]: | ||
if not self.enable_oper: | ||
return [] | ||
|
||
out = [] | ||
|
||
for name in self.oper_permissions: | ||
if fnmatch(oper_name, name): | ||
out.extend(self.oper_permissions[name]) | ||
|
||
return out | ||
|
||
def check_permissions(self, line: Line) -> list[str]: | ||
""" | ||
Return the permissions the sender of a given line has | ||
:param line: The line to check | ||
:return: a list of permission strings | ||
""" | ||
out: list[str] = [] | ||
out.extend(self.check_masks(str(line.hostmask))) | ||
|
||
if self.enable_oper and line.tags is not None and "oper" in line.tags: | ||
out.append("oper") | ||
|
||
if line.tags["oper"] != "": | ||
out.extend(self.check_oper(line.tags["oper"])) | ||
|
||
return super().check_permissions(line) |