-
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 406bd21
Showing
8 changed files
with
293 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,132 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Ignore example access files | ||
examples/*.json |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 David Schultz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# ircflags | ||
easy IRC bot access control |
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 @@ | ||
0.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,12 @@ | ||
from ircflags import Flags | ||
|
||
flags = Flags("access.json", "ABCDefg") | ||
|
||
flags.setFlags("lunchd", "+AeBf") | ||
print(flags.getFlags("lunchd")) | ||
flags.setFlags("lunchd", "+C", channel="#test") | ||
print(flags.getFlags("lunchd", channel="#test")) | ||
flags.setFlags("lunchd", "+*", channel="#test") | ||
print(flags.getFlags("lunchd", channel="#test")) | ||
flags.setFlags("lunchd", "-*", channel="#test") | ||
print(flags.getFlags("lunchd", channel="#test")) |
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,102 @@ | ||
from typing import List, Set | ||
from os.path import isfile | ||
import json | ||
|
||
class Flags(object): | ||
def __init__(self, | ||
file: str, | ||
validflags: str): | ||
|
||
if not validflags.isalpha(): | ||
raise ValueError("Flags can only be letters of the alphabet") | ||
|
||
self.file = file | ||
self.validflags = sorted(validflags) | ||
self.database = {} | ||
|
||
self._from_file() | ||
|
||
def _serialize(self, value: Set[str]) -> List[str]: | ||
return list(value) | ||
|
||
def _deserialize(self, value: List[str]) -> Set[str]: | ||
return set(value) | ||
|
||
def _from_file(self): | ||
if isfile(self.file): | ||
with open(self.file) as db_file: | ||
database = json.loads(db_file.read()) | ||
|
||
for t in database.keys(): | ||
if not t in self.database.keys(): | ||
self.database[t] = {} | ||
self.database[t].update({ | ||
k: self._deserialize(v) for k,v in database[t].items() | ||
}) | ||
|
||
def _write(self): | ||
database_serialized = { | ||
t: { | ||
k: self._serialize(v) for k,v in self.database[t].items() | ||
} for t in self.database.keys() | ||
} | ||
data = json.dumps(database_serialized, indent=4, sort_keys=True) | ||
with open(self.file, "w") as db_file: | ||
db_file.write(data) | ||
|
||
def getFlags(self, | ||
user: str, | ||
default: str = '', | ||
channel: str = None): | ||
|
||
user = user.lower() | ||
|
||
if channel and channel.lower() in self.database.keys() and user in self.database[channel]: | ||
target = channel.lower() | ||
else: | ||
target = "global" | ||
|
||
try: | ||
value = self.database[target][user] | ||
except KeyError: | ||
value = default | ||
|
||
return "".join(sorted(value)) | ||
|
||
def setFlags(self, | ||
user: str, | ||
value: str, | ||
channel: str = None): | ||
|
||
user = user.lower() | ||
|
||
if channel: | ||
target = channel.lower() | ||
else: | ||
target = "global" | ||
|
||
if not target in self.database.keys(): | ||
self.database[target] = {} | ||
|
||
flags = {f for f in self.database[target].get(user, "")} | ||
op = value[0] | ||
if not op in "+-": | ||
raise ValueError(f"{op} is not a valid operator") | ||
for c in value[1:]: | ||
if c in "+-": | ||
op = c | ||
elif c in self.validflags: | ||
if op == "+" and not c in flags: | ||
flags.add(c) | ||
elif op == "-" and c in flags: | ||
flags.remove(c) | ||
elif c == "*": | ||
if op == "+": | ||
flags = set("".join(self.validflags)) | ||
elif op == "-": | ||
flags = set() | ||
else: | ||
raise ValueError(f"{c} is not a valid flag") | ||
|
||
self.database[target][user] = flags | ||
self._write() |
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,23 @@ | ||
import setuptools | ||
|
||
with open("VERSION", "r") as f: | ||
version = f.read().strip() | ||
|
||
setuptools.setup( | ||
name="ircflags", | ||
version=version, | ||
author="examknow", | ||
author_email="[email protected]", | ||
description="easy IRC bot access control", | ||
url="https://github.com/examknow/ircflags", | ||
packages=setuptools.find_packages(), | ||
package_data={"ircflags": ["py.typed"]}, | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Operating System :: POSIX", | ||
"Operating System :: Microsoft :: Windows" | ||
], | ||
python_requires='>=3.6', | ||
) |