Compare commits
No commits in common. "master" and "master" have entirely different histories.
42 changed files with 207 additions and 1037 deletions
|
@ -1,21 +0,0 @@
|
||||||
# http://editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
charset = utf-8
|
|
||||||
end_of_line = lf
|
|
||||||
|
|
||||||
[*.bat]
|
|
||||||
indent_style = tab
|
|
||||||
end_of_line = crlf
|
|
||||||
|
|
||||||
[LICENSE]
|
|
||||||
insert_final_newline = false
|
|
||||||
|
|
||||||
[Makefile]
|
|
||||||
indent_style = tab
|
|
107
.gitignore
vendored
107
.gitignore
vendored
|
@ -1,106 +1,5 @@
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.txt
|
||||||
*$py.class
|
*.xls
|
||||||
|
.~lock.Banana.xls#
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
env/
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
|
|
||||||
# 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/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
.python-version
|
|
||||||
|
|
||||||
# celery beat schedule file
|
|
||||||
celerybeat-schedule
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# dotenv
|
|
||||||
.env
|
|
||||||
|
|
||||||
# virtualenv
|
|
||||||
.venv
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
|
|
||||||
# IDE settings
|
|
||||||
.vscode/
|
|
||||||
|
|
13
AUTHORS.rst
13
AUTHORS.rst
|
@ -1,13 +0,0 @@
|
||||||
Development Lead
|
|
||||||
================
|
|
||||||
|
|
||||||
* itec <itec@ventuordici.org>
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
============
|
|
||||||
|
|
||||||
* Autoscatto
|
|
||||||
* Baku
|
|
||||||
* Boyska
|
|
||||||
* Encrypt
|
|
||||||
* Thegamer
|
|
|
@ -1,8 +0,0 @@
|
||||||
.. highlight:: shell
|
|
||||||
|
|
||||||
============
|
|
||||||
Contributing
|
|
||||||
============
|
|
||||||
|
|
||||||
Contributions are welcome, and they are greatly appreciated! Every little bit
|
|
||||||
helps, and credit will always be given.
|
|
|
@ -1,8 +0,0 @@
|
||||||
=======
|
|
||||||
History
|
|
||||||
=======
|
|
||||||
|
|
||||||
0.1.0 (2020-09-25)
|
|
||||||
------------------
|
|
||||||
|
|
||||||
* NOPE.
|
|
22
LICENSE
22
LICENSE
|
@ -1,22 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020, itec
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
11
MANIFEST.in
11
MANIFEST.in
|
@ -1,11 +0,0 @@
|
||||||
include AUTHORS.rst
|
|
||||||
include CONTRIBUTING.rst
|
|
||||||
include HISTORY.rst
|
|
||||||
include LICENSE
|
|
||||||
include README.rst
|
|
||||||
|
|
||||||
recursive-include tests *
|
|
||||||
recursive-exclude * __pycache__
|
|
||||||
recursive-exclude * *.py[co]
|
|
||||||
|
|
||||||
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
|
|
85
Makefile
85
Makefile
|
@ -1,85 +0,0 @@
|
||||||
.PHONY: clean clean-test clean-pyc clean-build docs help
|
|
||||||
.DEFAULT_GOAL := help
|
|
||||||
|
|
||||||
define BROWSER_PYSCRIPT
|
|
||||||
import os, webbrowser, sys
|
|
||||||
|
|
||||||
from urllib.request import pathname2url
|
|
||||||
|
|
||||||
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
|
|
||||||
endef
|
|
||||||
export BROWSER_PYSCRIPT
|
|
||||||
|
|
||||||
define PRINT_HELP_PYSCRIPT
|
|
||||||
import re, sys
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
|
|
||||||
if match:
|
|
||||||
target, help = match.groups()
|
|
||||||
print("%-20s %s" % (target, help))
|
|
||||||
endef
|
|
||||||
export PRINT_HELP_PYSCRIPT
|
|
||||||
|
|
||||||
BROWSER := python -c "$$BROWSER_PYSCRIPT"
|
|
||||||
|
|
||||||
help:
|
|
||||||
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
|
|
||||||
|
|
||||||
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
|
|
||||||
|
|
||||||
clean-build: ## remove build artifacts
|
|
||||||
rm -fr build/
|
|
||||||
rm -fr dist/
|
|
||||||
rm -fr .eggs/
|
|
||||||
find . -name '*.egg-info' -exec rm -fr {} +
|
|
||||||
find . -name '*.egg' -exec rm -f {} +
|
|
||||||
|
|
||||||
clean-pyc: ## remove Python file artifacts
|
|
||||||
find . -name '*.pyc' -exec rm -f {} +
|
|
||||||
find . -name '*.pyo' -exec rm -f {} +
|
|
||||||
find . -name '*~' -exec rm -f {} +
|
|
||||||
find . -name '__pycache__' -exec rm -fr {} +
|
|
||||||
|
|
||||||
clean-test: ## remove test and coverage artifacts
|
|
||||||
rm -fr .tox/
|
|
||||||
rm -f .coverage
|
|
||||||
rm -fr htmlcov/
|
|
||||||
rm -fr .pytest_cache
|
|
||||||
|
|
||||||
lint: ## check style with flake8
|
|
||||||
flake8 banana tests
|
|
||||||
|
|
||||||
test: ## run tests quickly with the default Python
|
|
||||||
pytest
|
|
||||||
|
|
||||||
test-all: ## run tests on every Python version with tox
|
|
||||||
tox
|
|
||||||
|
|
||||||
coverage: ## check code coverage quickly with the default Python
|
|
||||||
coverage run --source banana -m pytest
|
|
||||||
coverage report -m
|
|
||||||
coverage html
|
|
||||||
$(BROWSER) htmlcov/index.html
|
|
||||||
|
|
||||||
docs: ## generate Sphinx HTML documentation, including API docs
|
|
||||||
rm -f docs/banana.rst
|
|
||||||
rm -f docs/modules.rst
|
|
||||||
sphinx-apidoc -o docs/ banana
|
|
||||||
$(MAKE) -C docs clean
|
|
||||||
$(MAKE) -C docs html
|
|
||||||
$(BROWSER) docs/_build/html/index.html
|
|
||||||
|
|
||||||
servedocs: docs ## compile the docs watching for changes
|
|
||||||
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
|
|
||||||
|
|
||||||
release: dist ## package and upload a release
|
|
||||||
twine upload dist/*
|
|
||||||
|
|
||||||
dist: clean ## builds source and wheel package
|
|
||||||
python setup.py sdist
|
|
||||||
python setup.py bdist_wheel
|
|
||||||
ls -l dist
|
|
||||||
|
|
||||||
install: clean ## install the package to the active Python's site-packages
|
|
||||||
python setup.py install
|
|
24
README.md
24
README.md
|
@ -1,24 +0,0 @@
|
||||||
banana
|
|
||||||
======
|
|
||||||
|
|
||||||
![image](https://img.shields.io/travis/itec/banana.svg?label=banana&color=fedcba&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABgAAAAVCAYAAABc6S4mAAAACXBIWXMAAABmAAAAZgEHbzbCAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm%2B48GgAAA3lJREFUOI2tlW1olWUYx3%2F38zznOWfPOdvT2WkenRZae3GkbWRva2PVRkYYkawpyvqQ6CAalZiwihgVlCQYgaUzEwMJlvYhMEr6ECc13Ha%2BlGm23MZglrpZnb2ct%2Be577sPdcKCEem5Pt1cXPf1%2B%2F%2Fv%2B4ILihu1wBAwBXQCGEUGbFnbFpg1BNqxeRGoLGp32%2BLzqeNuqn6xOL5%2FY2AA2FJMB5GoK2KljghLjXi83qgFWosJaGt%2FyE5nczqrNcTCwnVDuEUDWCbPvLw5tOL0T2qiusLwAUoCwikWoK1llWXHYyKWSHpTjcuEBWAalBQDEAnZvNa%2FM9wA8NWQ77fVmnEAqclfN8Aw2PPRjrATLROuVMgz56Sz6mZRBZD3dO56AW9s7ihf8NjqpXmAg5%2Fmk4%2FUGWmAnE8ulWXOulbhwDtdHZHl771kLcO%2FFPR8vN7dGeNsj90AcHJEnZeawWtxcIttcfTV7oravQeOLhIEPLS%2FZGPP3MkXWkwv6ggXYMeXchI49n8clANPL6wQa4590JBZ%2BeDuRXq0w9QqXdN3OD9wcdQX27YF7wPIeGROjEgFJP8LEAWagTXxmGjYuT0%2B17npFdAypM4%2FWgna3dOfO7Xr%2FSzDvcGmwqXuj73BjMc%2BAAtoATYBDpACTCGoKHVESewGw1m%2FOuA%2F2b7YqGt80wRVqi9sL9FyZkUuT65962wif0Uy3BtssgwsgB8v6%2FFDQ3IG6AcQwCQQSRyIjK2sNm%2FyJX60TLhCIAqKhFEyrFU%2BArJSKuT%2BT3JDr%2B%2FNGj2tpnzuAavxrzL1%2Fc860fR2LjCdYQMwUQAkbJOlbkRcvud2a7brCbu89V6rJmSLUAHgS%2FzkGTnSdyT7yxcJv%2BzhWmO6b0PgbsfGAbiSJvnthNJr9%2BXVdJZuIPm3OKChsky8m9gatCZ%2BV87BU3LqmzEVzEqE0gjbwg9b6Lq44Xc1mze21Ri3CYHwFJMXU%2FwwNacWDI1r9fwRbybj0QV8d%2FUnFp7hzlCAXevuML1n7zddNyRmQwGMUEAELVMHtUYqJWTG09nZnNJZT8SlpurXNKnez7zTg%2BP6glR0A7%2F9e0rEVWcbeCocYF1zlWl03mUsWb5Q3Cr%2BWYMnyZ8YVWc%2FHJDT5y7pGV%2FyFvD1fGMo5snXA%2BuDFtVlIUqVFlGAdF6rrMeE%2FnPvHgbG5mtciD8AcJRb8mo4BE0AAAAASUVORK5CYII%3D%0A%20%20%20%20%20:target:%20https://travis-ci.com/itec/banana)
|
|
||||||
|
|
||||||
- Free software: MIT license
|
|
||||||
- Documentation: <https://git.lattuga.net/itec/banana>.
|
|
||||||
|
|
||||||
Features
|
|
||||||
--------
|
|
||||||
|
|
||||||
- Supports multiple, super-interesting bases: banana 🍌, ananas 🍍, ribes 🍇 avocado 🥑
|
|
||||||
- Encode and decode easily
|
|
||||||
- Check validity of encoded words
|
|
||||||
- Generate random words 🎲
|
|
||||||
- It's easy to support additional bases based on the same principles 🧩
|
|
||||||
|
|
||||||
|
|
||||||
Credits
|
|
||||||
-------
|
|
||||||
Thanks to Autoscatto, Baku, Boyska for suggestions and developement.
|
|
||||||
|
|
||||||
Special thanks to Stefano Bartezzaghi.
|
|
||||||
Loosely inspired by Stefano Bartezzaghi's book "Accavallavacca. Inventario di parole da gioco", Milano, Bompiani, 1992. ISBN 88-452-1948-8.
|
|
10
ananas2dec.py
Executable file
10
ananas2dec.py
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert ananas string to dec")
|
||||||
|
parser.add_argument("ananas", help="String to be converted")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.banana2dec(args.ananas, 1, 0))
|
10
avocado2dec.py
Executable file
10
avocado2dec.py
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert avocado string to dec")
|
||||||
|
parser.add_argument("avocado", help="String to be converted")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.banana2dec(args.avocado, 1, 0))
|
88
banana.py
Executable file
88
banana.py
Executable file
|
@ -0,0 +1,88 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
def dec2banana(num, dictstart = None, shiftend = None, minlength = None, dictionary = None):
|
||||||
|
#defaults
|
||||||
|
if dictstart is None: dictstart = 0
|
||||||
|
if shiftend is None: shiftend = 0
|
||||||
|
if minlength is None: minlength = 0
|
||||||
|
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")]
|
||||||
|
|
||||||
|
numdict = len(dictionary)
|
||||||
|
v = num
|
||||||
|
st = ""
|
||||||
|
l = 0
|
||||||
|
|
||||||
|
i = (numdict - 1 + dictstart + shiftend) % numdict
|
||||||
|
while not (v == 0 and i == (numdict - 1 + dictstart) % numdict and l >= minlength):
|
||||||
|
r = v % len(dictionary[i])
|
||||||
|
v = int(v / len(dictionary[i]))
|
||||||
|
st = dictionary[i][r] + st
|
||||||
|
i = (i - 1) % numdict
|
||||||
|
l += 1
|
||||||
|
|
||||||
|
return(st)
|
||||||
|
|
||||||
|
|
||||||
|
def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None):
|
||||||
|
#defaults
|
||||||
|
if dictstart is None: dictstart = 0
|
||||||
|
if shiftend is None: shiftend = 0
|
||||||
|
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
||||||
|
|
||||||
|
numdict = len(dictionary)
|
||||||
|
if (len(banana) - shiftend) % numdict != 0:
|
||||||
|
return("Banana non valida")
|
||||||
|
v = 0
|
||||||
|
for i in range(len(banana)):
|
||||||
|
r = (numdict + i + dictstart) % numdict
|
||||||
|
try:
|
||||||
|
v = v * len(dictionary[r]) + dictionary[r].index(banana[i])
|
||||||
|
except:
|
||||||
|
return("Carattere non valido in posizione", i+1)
|
||||||
|
|
||||||
|
return(v)
|
||||||
|
|
||||||
|
def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary = None):
|
||||||
|
import random
|
||||||
|
|
||||||
|
#defaults
|
||||||
|
if dictstart is None: dictstart = 0
|
||||||
|
if shiftend is None: shiftend = 0
|
||||||
|
if minlength is None: minlength = 6
|
||||||
|
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")]
|
||||||
|
|
||||||
|
numdict = len(dictionary)
|
||||||
|
st = ""
|
||||||
|
l = 0
|
||||||
|
|
||||||
|
i = (numdict - 1 + dictstart + shiftend) % numdict
|
||||||
|
while not (i == (numdict - 1 + dictstart) % numdict and l >= minlength):
|
||||||
|
r = random.randint(0, len(dictionary[i]) - 1)
|
||||||
|
st = dictionary[i][r] + st
|
||||||
|
i = (i - 1) % numdict
|
||||||
|
l += 1
|
||||||
|
|
||||||
|
return(st)
|
||||||
|
|
||||||
|
def isbanana(banana, dictstart = None, shiftend = None, dictionary = None):
|
||||||
|
#defaults
|
||||||
|
if dictstart is None: dictstart = 0
|
||||||
|
if shiftend is None: shiftend = 0
|
||||||
|
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
||||||
|
|
||||||
|
numdict = len(dictionary)
|
||||||
|
if (len(banana) - shiftend) % numdict != 0:
|
||||||
|
return(False)
|
||||||
|
for i in range(len(banana)):
|
||||||
|
r = (numdict + i + dictstart) % numdict
|
||||||
|
if banana[i] not in dictionary[r]:
|
||||||
|
return(False)
|
||||||
|
|
||||||
|
return(True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("Ciao sono la libreria banana")
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.7 KiB |
|
@ -1,6 +0,0 @@
|
||||||
"""Top-level package for banana."""
|
|
||||||
from .libbanana import *
|
|
||||||
|
|
||||||
__author__ = """itec"""
|
|
||||||
__email__ = "itec@ventuordici.org"
|
|
||||||
__version__ = "0.1.0"
|
|
103
banana/cli.py
103
banana/cli.py
|
@ -1,103 +0,0 @@
|
||||||
"""Console script for banana."""
|
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
import random
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import banana
|
|
||||||
|
|
||||||
|
|
||||||
def get_codec(args):
|
|
||||||
kwargs = {}
|
|
||||||
if args.alphabets:
|
|
||||||
kwargs["alphabets"] = args.alphabets
|
|
||||||
if args.shiftalpha:
|
|
||||||
kwargs["shiftalpha"] = args.shiftalpha
|
|
||||||
if args.alphaend:
|
|
||||||
kwargs["alphaend"] = args.alphaend
|
|
||||||
return banana.Codec(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def main_encode(args):
|
|
||||||
codec = get_codec(args)
|
|
||||||
kwargs = dict(num=args.num)
|
|
||||||
if args.minlength:
|
|
||||||
kwargs["minlength"] = args.minlength
|
|
||||||
print(codec.encode(**kwargs))
|
|
||||||
|
|
||||||
|
|
||||||
def main_decode(args):
|
|
||||||
print(get_codec(args).decode(args.word))
|
|
||||||
|
|
||||||
|
|
||||||
def main_check(args):
|
|
||||||
if get_codec(args).is_valid(args.word):
|
|
||||||
if not args.quiet:
|
|
||||||
print("yes")
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
|
||||||
if not args.quiet:
|
|
||||||
print("no")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main_random(args):
|
|
||||||
codec = get_codec(args)
|
|
||||||
kwargs = dict(minlength=args.minlength)
|
|
||||||
if args.seed:
|
|
||||||
kwargs["prng"] = random.Random(args.seed)
|
|
||||||
print(codec.random(**kwargs))
|
|
||||||
|
|
||||||
|
|
||||||
def colon_separated_list(s):
|
|
||||||
return s.split(":")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
parser = argparse.ArgumentParser(description="Convert number to banana")
|
|
||||||
parser.add_argument(
|
|
||||||
"--log-level", choices=["DEBUG", "INFO", "WARN", "ERROR"], default="WARN"
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--alphabets", "-a",
|
|
||||||
help="Set alphabets in colon-separated list",
|
|
||||||
type=colon_separated_list,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--shiftalpha", "-s", help="Set shift for alphabets", type=int, default=0
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--alphaend", "-e", help="Set ending alphabet", type=int, default=0
|
|
||||||
)
|
|
||||||
sub = parser.add_subparsers()
|
|
||||||
encode = sub.add_parser("encode", help="Convert number to word")
|
|
||||||
encode.add_argument("num", type=int)
|
|
||||||
encode.add_argument("--minlength", "-l", help="Set minimum length", type=int, default=1)
|
|
||||||
encode.set_defaults(func=main_encode)
|
|
||||||
|
|
||||||
decode = sub.add_parser("decode", help="Convert word to number")
|
|
||||||
decode.add_argument("word")
|
|
||||||
decode.set_defaults(func=main_decode)
|
|
||||||
|
|
||||||
check = sub.add_parser("check", help="Check if word is banana")
|
|
||||||
check.add_argument("word")
|
|
||||||
check.add_argument("--quiet", "-q", action="store_true")
|
|
||||||
check.set_defaults(func=main_check)
|
|
||||||
|
|
||||||
rand = sub.add_parser("random", help="Generate random banana")
|
|
||||||
rand.add_argument("--minlength", "-l", help="Set minimum length", type=int, default=6)
|
|
||||||
rand.add_argument("--seed", type=int, default=None)
|
|
||||||
rand.set_defaults(func=main_random)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
if not hasattr(args, "func"):
|
|
||||||
print("You need to select one subcommand. \nUse --help", file=sys.stderr)
|
|
||||||
# parser.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
logging.basicConfig(level=args.log_level)
|
|
||||||
args.func(args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# pragma: no cover
|
|
||||||
main()
|
|
|
@ -1,89 +0,0 @@
|
||||||
"""Main module."""
|
|
||||||
import logging
|
|
||||||
import random
|
|
||||||
|
|
||||||
log = logging.getLogger("libbanana")
|
|
||||||
|
|
||||||
|
|
||||||
class Codec:
|
|
||||||
def __init__(self, shiftalpha=0, alphaend=0, minlength=0, alphabets=None):
|
|
||||||
self.shiftalpha = shiftalpha
|
|
||||||
self.alphaend = alphaend
|
|
||||||
if alphabets is None:
|
|
||||||
self.alphabets = [list("bcdfglmnprstvz"), list("aeiou")]
|
|
||||||
else:
|
|
||||||
self.alphabets = alphabets
|
|
||||||
|
|
||||||
def encode(self, num, minlength=1):
|
|
||||||
alphabets = self.alphabets
|
|
||||||
numalpha = len(alphabets)
|
|
||||||
v = num
|
|
||||||
st = ""
|
|
||||||
length = 0
|
|
||||||
|
|
||||||
idx = (numalpha - 1 + self.shiftalpha + self.alphaend) % numalpha
|
|
||||||
while not (
|
|
||||||
v == 0
|
|
||||||
and idx == (numalpha - 1 + self.shiftalpha) % numalpha
|
|
||||||
and length >= minlength
|
|
||||||
):
|
|
||||||
r = v % len(alphabets[idx])
|
|
||||||
v = int(v / len(alphabets[idx]))
|
|
||||||
st = alphabets[idx][r] + st
|
|
||||||
idx = (idx + numalpha - 1) % numalpha
|
|
||||||
length += 1
|
|
||||||
|
|
||||||
return st
|
|
||||||
|
|
||||||
def decode(self, word):
|
|
||||||
alphabets = self.alphabets
|
|
||||||
|
|
||||||
numalpha = len(alphabets)
|
|
||||||
if (len(word) - self.alphaend) % numalpha != 0:
|
|
||||||
raise ValueError("Invalid banana")
|
|
||||||
v = 0
|
|
||||||
for i in range(len(word)):
|
|
||||||
r = (numalpha + i + self.shiftalpha) % numalpha
|
|
||||||
try:
|
|
||||||
v = v * len(alphabets[r]) + alphabets[r].index(word[i])
|
|
||||||
except (ValueError, KeyError):
|
|
||||||
raise ValueError("Invalid character in position %d" % i + 1)
|
|
||||||
|
|
||||||
return v
|
|
||||||
|
|
||||||
def is_valid(self, word):
|
|
||||||
alphabets = self.alphabets
|
|
||||||
|
|
||||||
numalpha = len(alphabets)
|
|
||||||
if (len(word) - self.alphaend) % numalpha != 0:
|
|
||||||
return False
|
|
||||||
for i in range(len(word)):
|
|
||||||
r = (numalpha + i + self.shiftalpha) % numalpha
|
|
||||||
if word[i] not in alphabets[r]:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def random(self, minlength=6, prng=random.Random()):
|
|
||||||
numalpha = len(self.alphabets)
|
|
||||||
word = ""
|
|
||||||
|
|
||||||
if minlength < 1:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
curr_alpha = (numalpha - 1 + self.shiftalpha + self.alphaend) % numalpha
|
|
||||||
final_alpha = (numalpha - 1 + self.shiftalpha) % numalpha
|
|
||||||
while curr_alpha != final_alpha or len(word) < minlength:
|
|
||||||
word = prng.choice(self.alphabets[curr_alpha]) + word
|
|
||||||
curr_alpha = (curr_alpha - 1) % numalpha
|
|
||||||
|
|
||||||
return word
|
|
||||||
|
|
||||||
|
|
||||||
class BananaCodec(Codec):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print("Hi I'm the basebanana library")
|
|
13
banana2dec.py
Executable file
13
banana2dec.py
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert banana string to dec")
|
||||||
|
parser.add_argument("banana", help="String to be converted")
|
||||||
|
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||||
|
parser.add_argument("--dictstart", help="Set starting dictionary", type=int)
|
||||||
|
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.banana2dec(args.banana, args.dictstart, args.shiftend, args.dictionary))
|
13
bananarandom.py
Executable file
13
bananarandom.py
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Generate random banana")
|
||||||
|
parser.add_argument("--dictstart", help="Set starting dictionary", type=int)
|
||||||
|
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int)
|
||||||
|
parser.add_argument("--minlength", help="Set minimum length", type=int)
|
||||||
|
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.bananarandom(args.dictstart, args.shiftend, args.minlength, args.dictionary))
|
11
dec2ananas.py
Executable file
11
dec2ananas.py
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert dec number to ananas")
|
||||||
|
parser.add_argument("num", help="Number to be converted", type=int)
|
||||||
|
parser.add_argument("--minlength", help="Set minimum length", type=int)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.dec2banana(args.num, 1, 0, args.minlength))
|
11
dec2avocado.py
Executable file
11
dec2avocado.py
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert dec number to avocado")
|
||||||
|
parser.add_argument("num", help="Number to be converted", type=int)
|
||||||
|
parser.add_argument("--minlength", help="Set minimum length", type=int)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.dec2banana(args.num, 1, 1, args.minlength))
|
14
dec2banana.py
Executable file
14
dec2banana.py
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert dec number to banana")
|
||||||
|
parser.add_argument("num", help="Number to be converted", type=int)
|
||||||
|
parser.add_argument("--dictstart", help="Set starting dictionary", type=int)
|
||||||
|
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int)
|
||||||
|
parser.add_argument("--minlength", help="Set minimum length", type=int)
|
||||||
|
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.dec2banana(args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary))
|
11
dec2ribes.py
Executable file
11
dec2ribes.py
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert dec number to ribes")
|
||||||
|
parser.add_argument("num", help="Number to be converted", type=int)
|
||||||
|
parser.add_argument("--minlength", help="Set minimum length", type=int)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.dec2banana(args.num, 1, 1, args.minlength))
|
|
@ -1,20 +0,0 @@
|
||||||
# Minimal makefile for Sphinx documentation
|
|
||||||
#
|
|
||||||
|
|
||||||
# You can set these variables from the command line.
|
|
||||||
SPHINXOPTS =
|
|
||||||
SPHINXBUILD = python -msphinx
|
|
||||||
SPHINXPROJ = banana
|
|
||||||
SOURCEDIR = .
|
|
||||||
BUILDDIR = _build
|
|
||||||
|
|
||||||
# Put it first so that "make" without argument is like "make help".
|
|
||||||
help:
|
|
||||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
||||||
|
|
||||||
.PHONY: help Makefile
|
|
||||||
|
|
||||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
||||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
||||||
%: Makefile
|
|
||||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
|
@ -1 +0,0 @@
|
||||||
.. include:: ../AUTHORS.rst
|
|
|
@ -1,30 +0,0 @@
|
||||||
banana package
|
|
||||||
==============
|
|
||||||
|
|
||||||
Submodules
|
|
||||||
----------
|
|
||||||
|
|
||||||
banana.bananalib module
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
.. automodule:: banana.bananalib
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
banana.cli module
|
|
||||||
-----------------
|
|
||||||
|
|
||||||
.. automodule:: banana.cli
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
|
|
||||||
Module contents
|
|
||||||
---------------
|
|
||||||
|
|
||||||
.. automodule:: banana
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
165
docs/conf.py
165
docs/conf.py
|
@ -1,165 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
#
|
|
||||||
# banana documentation build configuration file, created by
|
|
||||||
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
|
|
||||||
#
|
|
||||||
# This file is execfile()d with the current directory set to its
|
|
||||||
# containing dir.
|
|
||||||
#
|
|
||||||
# Note that not all possible configuration values are present in this
|
|
||||||
# autogenerated file.
|
|
||||||
#
|
|
||||||
# All configuration values have a default; values that are commented out
|
|
||||||
# serve to show the default.
|
|
||||||
|
|
||||||
# If extensions (or modules to document with autodoc) are in another
|
|
||||||
# directory, add these directories to sys.path here. If the directory is
|
|
||||||
# relative to the documentation root, use os.path.abspath to make it
|
|
||||||
# absolute, like shown here.
|
|
||||||
#
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
sys.path.insert(0, os.path.abspath('..'))
|
|
||||||
|
|
||||||
import banana
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------
|
|
||||||
|
|
||||||
# If your documentation needs a minimal Sphinx version, state it here.
|
|
||||||
#
|
|
||||||
# needs_sphinx = '1.0'
|
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be
|
|
||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
|
||||||
extensions = [
|
|
||||||
"sphinx.ext.autodoc",
|
|
||||||
"sphinx.ext.viewcode",
|
|
||||||
"m2r",
|
|
||||||
"sphinxemoji.sphinxemoji",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
|
||||||
templates_path = ['_templates']
|
|
||||||
|
|
||||||
# The suffix(es) of source filenames.
|
|
||||||
# You can specify multiple suffix as a list of string:
|
|
||||||
#
|
|
||||||
source_suffix = ['.rst', '.md']
|
|
||||||
#source_suffix = '.rst'
|
|
||||||
|
|
||||||
# The master toctree document.
|
|
||||||
master_doc = 'index'
|
|
||||||
|
|
||||||
# General information about the project.
|
|
||||||
project = 'banana'
|
|
||||||
copyright = "2020, itec"
|
|
||||||
author = "itec"
|
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement
|
|
||||||
# for |version| and |release|, also used in various other places throughout
|
|
||||||
# the built documents.
|
|
||||||
#
|
|
||||||
# The short X.Y version.
|
|
||||||
version = banana.__version__
|
|
||||||
# The full version, including alpha/beta/rc tags.
|
|
||||||
release = banana.__version__
|
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
|
||||||
# for a list of supported languages.
|
|
||||||
#
|
|
||||||
# This is also used if you do content translation via gettext catalogs.
|
|
||||||
# Usually you set "language" from the command line for these cases.
|
|
||||||
language = None
|
|
||||||
|
|
||||||
# List of patterns, relative to source directory, that match files and
|
|
||||||
# directories to ignore when looking for source files.
|
|
||||||
# This patterns also effect to html_static_path and html_extra_path
|
|
||||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
|
||||||
|
|
||||||
# The name of the Pygments (syntax highlighting) style to use.
|
|
||||||
pygments_style = 'sphinx'
|
|
||||||
|
|
||||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
|
||||||
todo_include_todos = False
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for HTML output -------------------------------------------
|
|
||||||
|
|
||||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
||||||
# a list of builtin themes.
|
|
||||||
#
|
|
||||||
html_theme = 'alabaster'
|
|
||||||
|
|
||||||
# Theme options are theme-specific and customize the look and feel of a
|
|
||||||
# theme further. For a list of options available for each theme, see the
|
|
||||||
# documentation.
|
|
||||||
#
|
|
||||||
# html_theme_options = {}
|
|
||||||
|
|
||||||
# Add any paths that contain custom static files (such as style sheets) here,
|
|
||||||
# relative to this directory. They are copied after the builtin static files,
|
|
||||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
||||||
html_static_path = ['_static']
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for HTMLHelp output ---------------------------------------
|
|
||||||
|
|
||||||
# Output file base name for HTML help builder.
|
|
||||||
htmlhelp_basename = 'bananadoc'
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for LaTeX output ------------------------------------------
|
|
||||||
|
|
||||||
latex_elements = {
|
|
||||||
# The paper size ('letterpaper' or 'a4paper').
|
|
||||||
#
|
|
||||||
# 'papersize': 'letterpaper',
|
|
||||||
|
|
||||||
# The font size ('10pt', '11pt' or '12pt').
|
|
||||||
#
|
|
||||||
# 'pointsize': '10pt',
|
|
||||||
|
|
||||||
# Additional stuff for the LaTeX preamble.
|
|
||||||
#
|
|
||||||
# 'preamble': '',
|
|
||||||
|
|
||||||
# Latex figure (float) alignment
|
|
||||||
#
|
|
||||||
# 'figure_align': 'htbp',
|
|
||||||
}
|
|
||||||
|
|
||||||
# Grouping the document tree into LaTeX files. List of tuples
|
|
||||||
# (source start file, target name, title, author, documentclass
|
|
||||||
# [howto, manual, or own class]).
|
|
||||||
latex_documents = [
|
|
||||||
(master_doc, 'banana.tex',
|
|
||||||
'banana Documentation',
|
|
||||||
'itec', 'manual'),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for manual page output ------------------------------------
|
|
||||||
|
|
||||||
# One entry per manual page. List of tuples
|
|
||||||
# (source start file, name, description, authors, manual section).
|
|
||||||
man_pages = [
|
|
||||||
(master_doc, 'banana',
|
|
||||||
'banana Documentation',
|
|
||||||
[author], 1)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for Texinfo output ----------------------------------------
|
|
||||||
|
|
||||||
# Grouping the document tree into Texinfo files. List of tuples
|
|
||||||
# (source start file, target name, title, author,
|
|
||||||
# dir menu entry, description, category)
|
|
||||||
texinfo_documents = [
|
|
||||||
(master_doc, 'banana',
|
|
||||||
'banana Documentation',
|
|
||||||
author,
|
|
||||||
'banana',
|
|
||||||
'One line description of project.',
|
|
||||||
'Miscellaneous'),
|
|
||||||
]
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
.. include:: ../CONTRIBUTING.rst
|
|
|
@ -1 +0,0 @@
|
||||||
.. include:: ../HISTORY.rst
|
|
|
@ -1,20 +0,0 @@
|
||||||
Welcome to banana's documentation!
|
|
||||||
======================================
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 2
|
|
||||||
:caption: Contents:
|
|
||||||
|
|
||||||
readme
|
|
||||||
installation
|
|
||||||
usage
|
|
||||||
modules
|
|
||||||
contributing
|
|
||||||
authors
|
|
||||||
history
|
|
||||||
|
|
||||||
Indices and tables
|
|
||||||
==================
|
|
||||||
* :ref:`genindex`
|
|
||||||
* :ref:`modindex`
|
|
||||||
* :ref:`search`
|
|
|
@ -1,51 +0,0 @@
|
||||||
.. highlight:: shell
|
|
||||||
|
|
||||||
============
|
|
||||||
Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
|
|
||||||
Stable release
|
|
||||||
--------------
|
|
||||||
|
|
||||||
To install banana, run this command in your terminal:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
$ pip install banana
|
|
||||||
|
|
||||||
This is the preferred method to install banana, as it will always install the most recent stable release.
|
|
||||||
|
|
||||||
If you don't have `pip`_ installed, this `Python installation guide`_ can guide
|
|
||||||
you through the process.
|
|
||||||
|
|
||||||
.. _pip: https://pip.pypa.io
|
|
||||||
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
|
|
||||||
|
|
||||||
|
|
||||||
From sources
|
|
||||||
------------
|
|
||||||
|
|
||||||
The sources for banana can be downloaded from the `Gogs repo`_.
|
|
||||||
|
|
||||||
You can either clone the public repository:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
$ git clone https://git.lattuga.net/itec/banana
|
|
||||||
|
|
||||||
Or download the `tarball`_:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
$ curl -OJL https://git.lattuga.net/itec/banana/archive/master.tar.gz
|
|
||||||
|
|
||||||
Once you have a copy of the source, you can install it with:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
$ python setup.py install
|
|
||||||
|
|
||||||
|
|
||||||
.. _Gogs repo: https://git.lattuga.net/itec/banana
|
|
||||||
.. _tarball: https://git.lattuga.net/itec/banana/archive/master.tar.gz
|
|
|
@ -1,36 +0,0 @@
|
||||||
@ECHO OFF
|
|
||||||
|
|
||||||
pushd %~dp0
|
|
||||||
|
|
||||||
REM Command file for Sphinx documentation
|
|
||||||
|
|
||||||
if "%SPHINXBUILD%" == "" (
|
|
||||||
set SPHINXBUILD=python -msphinx
|
|
||||||
)
|
|
||||||
set SOURCEDIR=.
|
|
||||||
set BUILDDIR=_build
|
|
||||||
set SPHINXPROJ=banana
|
|
||||||
|
|
||||||
if "%1" == "" goto help
|
|
||||||
|
|
||||||
%SPHINXBUILD% >NUL 2>NUL
|
|
||||||
if errorlevel 9009 (
|
|
||||||
echo.
|
|
||||||
echo.The Sphinx module was not found. Make sure you have Sphinx installed,
|
|
||||||
echo.then set the SPHINXBUILD environment variable to point to the full
|
|
||||||
echo.path of the 'sphinx-build' executable. Alternatively you may add the
|
|
||||||
echo.Sphinx directory to PATH.
|
|
||||||
echo.
|
|
||||||
echo.If you don't have Sphinx installed, grab it from
|
|
||||||
echo.http://sphinx-doc.org/
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
||||||
goto end
|
|
||||||
|
|
||||||
:help
|
|
||||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
|
|
||||||
|
|
||||||
:end
|
|
||||||
popd
|
|
|
@ -1,7 +0,0 @@
|
||||||
banana
|
|
||||||
======
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 4
|
|
||||||
|
|
||||||
banana
|
|
|
@ -1,5 +0,0 @@
|
||||||
Readme
|
|
||||||
------
|
|
||||||
|
|
||||||
.. mdinclude:: ../README.md
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
=====
|
|
||||||
Usage
|
|
||||||
=====
|
|
||||||
To use banana in a project
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from banana import bananalib
|
|
||||||
|
|
||||||
|
|
||||||
======
|
|
||||||
Script
|
|
||||||
======
|
|
||||||
Available cli scripts:
|
|
||||||
|
|
||||||
|
|
13
isbanana.py
Executable file
13
isbanana.py
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Checks if string is banana")
|
||||||
|
parser.add_argument("banana", help="String to be checked")
|
||||||
|
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+')
|
||||||
|
parser.add_argument("--dictstart", help="Set starting dictionary", type=int)
|
||||||
|
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.isbanana(args.banana, args.dictstart, args.shiftend, args.dictionary))
|
|
@ -1,15 +0,0 @@
|
||||||
pip==23.2.1
|
|
||||||
bump2version==0.5.11
|
|
||||||
wheel==0.33.6
|
|
||||||
watchdog==0.9.0
|
|
||||||
flake8==3.7.8
|
|
||||||
tox==4.11.3
|
|
||||||
coverage==4.5.4
|
|
||||||
Sphinx==1.8.5
|
|
||||||
m2r==0.2.1
|
|
||||||
twine==1.14.0
|
|
||||||
sphinxemoji==0.1.7
|
|
||||||
|
|
||||||
|
|
||||||
pytest==6.2.5
|
|
||||||
pytest-runner==5.1
|
|
10
ribes2dec.py
Executable file
10
ribes2dec.py
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import banana
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Convert ribes string to dec")
|
||||||
|
parser.add_argument("ribes", help="String to be converted")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
print(banana.banana2dec(args.ribes, 1, 0))
|
25
setup.cfg
25
setup.cfg
|
@ -1,25 +0,0 @@
|
||||||
[bumpversion]
|
|
||||||
current_version = 0.1.0
|
|
||||||
commit = True
|
|
||||||
tag = True
|
|
||||||
|
|
||||||
[bumpversion:file:setup.py]
|
|
||||||
search = version='{current_version}'
|
|
||||||
replace = version='{new_version}'
|
|
||||||
|
|
||||||
[bumpversion:file:banana/__init__.py]
|
|
||||||
search = __version__ = '{current_version}'
|
|
||||||
replace = __version__ = '{new_version}'
|
|
||||||
|
|
||||||
[bdist_wheel]
|
|
||||||
universal = 1
|
|
||||||
|
|
||||||
[flake8]
|
|
||||||
exclude = docs
|
|
||||||
|
|
||||||
[aliases]
|
|
||||||
# Define setup.py command aliases here
|
|
||||||
test = pytest
|
|
||||||
|
|
||||||
[tool:pytest]
|
|
||||||
addopts = --ignore=setup.py
|
|
54
setup.py
54
setup.py
|
@ -1,54 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""The setup script."""
|
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
|
||||||
|
|
||||||
with open("README.md") as readme_file:
|
|
||||||
readme = readme_file.read()
|
|
||||||
|
|
||||||
with open("HISTORY.rst") as history_file:
|
|
||||||
history = history_file.read()
|
|
||||||
|
|
||||||
requirements = []
|
|
||||||
|
|
||||||
setup_requirements = ["pytest-runner"]
|
|
||||||
|
|
||||||
test_requirements = ["pytest>=3"]
|
|
||||||
|
|
||||||
setup(
|
|
||||||
author="itec",
|
|
||||||
author_email="itec@ventuordici.org",
|
|
||||||
python_requires=">=3.5",
|
|
||||||
classifiers=[
|
|
||||||
"Development Status :: 2 - Pre-Alpha",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Natural Language :: English",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Programming Language :: Python :: 3.5",
|
|
||||||
"Programming Language :: Python :: 3.6",
|
|
||||||
"Programming Language :: Python :: 3.7",
|
|
||||||
"Programming Language :: Python :: 3.8",
|
|
||||||
],
|
|
||||||
description="basebanana",
|
|
||||||
entry_points={
|
|
||||||
"console_scripts": [
|
|
||||||
"basebanana=banana.cli:main",
|
|
||||||
"banana=banana.cli:main",
|
|
||||||
]
|
|
||||||
},
|
|
||||||
install_requires=requirements,
|
|
||||||
license="MIT license",
|
|
||||||
long_description=readme + "\n\n" + history,
|
|
||||||
include_package_data=True,
|
|
||||||
keywords="basebanana",
|
|
||||||
name="basebanana",
|
|
||||||
packages=find_packages(include=["banana", "banana.*"]),
|
|
||||||
setup_requires=setup_requirements,
|
|
||||||
test_suite="tests",
|
|
||||||
tests_require=test_requirements,
|
|
||||||
url="https://git.lattuga.net/itec/banana",
|
|
||||||
version="0.2.0",
|
|
||||||
zip_safe=False,
|
|
||||||
)
|
|
|
@ -1 +0,0 @@
|
||||||
"""Unit test package for banana."""
|
|
|
@ -1,64 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""Tests for `banana` package."""
|
|
||||||
import random
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from banana import BananaCodec
|
|
||||||
|
|
||||||
banana_conversions = {
|
|
||||||
"be": 1,
|
|
||||||
"da": 10,
|
|
||||||
"bema" : 100,
|
|
||||||
"duga": 1000,
|
|
||||||
"bibiva": 10000,
|
|
||||||
"galopa": 100000,
|
|
||||||
"bivucasa": 1000000,
|
|
||||||
"beba": 70,
|
|
||||||
"zu": 69,
|
|
||||||
"bezu": 139,
|
|
||||||
"nana": 2485,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=banana_conversions.items())
|
|
||||||
def banana_known(request):
|
|
||||||
yield request.param
|
|
||||||
|
|
||||||
|
|
||||||
banana_codec = BananaCodec()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana_to_dec_known(banana_known):
|
|
||||||
word, value = banana_known
|
|
||||||
assert banana_codec.decode(word) == value
|
|
||||||
|
|
||||||
|
|
||||||
def test_dec_to_banana_known(banana_known):
|
|
||||||
word, value = banana_known
|
|
||||||
assert banana_codec.encode(value) == word
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana_is_banana(banana_known):
|
|
||||||
assert banana_codec.is_valid(banana_known[0])
|
|
||||||
|
|
||||||
|
|
||||||
def test_banana2dec_prefix_ba(banana_known):
|
|
||||||
"""un ba all'inizio non cambia nulla!"""
|
|
||||||
word, value = banana_known
|
|
||||||
for prefix in ("ba", "baba", "bababa"):
|
|
||||||
assert banana_codec.decode(prefix + word) == value
|
|
||||||
|
|
||||||
|
|
||||||
def test_answer_to_life_the_universe_and_everything():
|
|
||||||
banana = banana_codec.decode("banana")
|
|
||||||
assert banana != 42
|
|
||||||
assert banana == 2485
|
|
||||||
|
|
||||||
|
|
||||||
def test_random_len_0():
|
|
||||||
assert banana_codec.random(minlength=0) == ""
|
|
||||||
|
|
30
tox.ini
30
tox.ini
|
@ -1,30 +0,0 @@
|
||||||
[tox]
|
|
||||||
envlist = py35, py36, py37, py38, py39, py310, py311, flake8
|
|
||||||
|
|
||||||
[travis]
|
|
||||||
python =
|
|
||||||
3.11: py311
|
|
||||||
3.10: py310
|
|
||||||
3.9: py39
|
|
||||||
3.8: py38
|
|
||||||
3.7: py37
|
|
||||||
3.6: py36
|
|
||||||
3.5: py35
|
|
||||||
|
|
||||||
[testenv:flake8]
|
|
||||||
basepython = python
|
|
||||||
deps = flake8
|
|
||||||
commands = flake8 banana tests
|
|
||||||
|
|
||||||
[testenv]
|
|
||||||
setenv =
|
|
||||||
PYTHONPATH = {toxinidir}
|
|
||||||
deps =
|
|
||||||
-r{toxinidir}/requirements_dev.txt
|
|
||||||
; If you want to make tox run the tests with the same versions, create a
|
|
||||||
; requirements.txt with the pinned versions and uncomment the following line:
|
|
||||||
; -r{toxinidir}/requirements.txt
|
|
||||||
commands =
|
|
||||||
pip install -U pip
|
|
||||||
pytest --basetemp={envtmpdir}
|
|
||||||
|
|
Loading…
Reference in a new issue