diff --git a/.glotter.yml b/.glotter.yml index 2f818124e..85b4ed937 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -33,6 +33,94 @@ projects: - " *" transformations: - "splitlines" + base64_encode_decode: + words: + - "base64" + - "encode" + - "decode" + requires_parameters: true + tests: + base64_encode_valid: + params: + - name: "lowercase string" + input: '"encode" "hello world"' + expected: "aGVsbG8gd29ybGQ=" + - name: "long string" + input: '"encode" "They swam along the boat at incredible speeds."' + expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg==" + - name: "numbers" + input: '"encode" "1234567890"' + expected: "MTIzNDU2Nzg5MA==" + - name: "symbols" + input: | + "encode" "x!\\"#$%&'()*+,-./:;<=>?@[\\\\]^_`{|}~" + expected: "eCEiIyQlJicoKSorLC0uLzo7PD0+P0BbXF1eX2B7fH1+" + - name: "all base64 characters" + input: '"encode" "! }gggIIT55;qqs!!Gjjb??=~~2$$+;;i::x..4kk,ppnoo"' + expected: "ISAgfWdnZ0lJVDU1O3FxcyEhR2pqYj8/PX5+MiQkKzs7aTo6eC4uNGtrLHBwbm9v" + transformations: + - "strip" + base64_decode_valid: + params: + - name: "lowercase string" + input: '"decode" "aGVsbG8gd29ybGQ="' + expected: "hello world" + - name: "long string" + input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg=="' + expected: "They swam along the boat at incredible speeds." + - name: "numbers" + input: '"decode" "MTIzNDU2Nzg5MA=="' + expected: "1234567890" + - name: "symbols" + input: '"decode" "eCEiIyQlJicoKSorLC0uLzo7PD0+P0BbXF1eX2B7fH1+"' + expected: "x!\"#$%&'()*+,-./:;<=>?@[\\\\]^_`{|}~" + - name: "all base64 characters" + input: '"decode" "ISAgfWdnZ0lJVDU1O3FxcyEhR2pqYj8/PX5+MiQkKzs7aTo6eC4uNGtrLHBwbm9v"' + expected: "! }gggIIT55;qqs!!Gjjb??=~~2$$+;;i::x..4kk,ppnoo" + transformations: + - "strip" + base64_invalid_inputs: + params: + - name: "no input" + input: null + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "invalid mode" + input: '"blue" "Oh look a Pascal triangle"' + expected: "Usage: please provide a mode and a string to encode/decode" + transformations: + - "strip" + base64_invalid_encode: + params: + - name: "missing string" + input: '"encode"' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "empty string" + input: '"encode" ""' + expected: "Usage: please provide a mode and a string to encode/decode" + transformations: + - "strip" + base64_invalid_decode: + params: + - name: "missing string" + input: '"decode"' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "empty string" + input: '"decode" ""' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "length number not multiple of 4" + input: '"decode" "hello+world"' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "invalid characters" + input: '"decode" "hello world="' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "too many pad characters at end" + input: '"decode" "MTIzNDU2Nzg5M==="' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "pad characters in middle" + input: '"decode" "MTIzNDU2=Nzg5M=="' + expected: "Usage: please provide a mode and a string to encode/decode" + transformations: + - "strip" binarysearch: words: - "binary" diff --git a/archive/p/python/base64_encode_decode.py b/archive/p/python/base64_encode_decode.py new file mode 100644 index 000000000..cb67cf4ec --- /dev/null +++ b/archive/p/python/base64_encode_decode.py @@ -0,0 +1,40 @@ +import base64 +import binascii +import sys +from typing import NoReturn + + +def usage() -> NoReturn: + print("Usage: please provide a mode and a string to encode/decode") + sys.exit(1) + + +def base64_encode(s: str) -> str: + return base64.b64encode(s.encode("ascii")).decode("ascii") + + +def base64_decode(s: str) -> str: + return base64.b64decode(s.encode("ascii")).decode("ascii") + + +def main() -> None | NoReturn: + if len(sys.argv) < 3 or not sys.argv[2]: + usage() + + mode = sys.argv[1] + s = sys.argv[2] + if mode == "encode": + result = base64_encode(s) + elif mode == "decode": + try: + result = base64_decode(s) + except binascii.Error: + usage() + else: + usage() + + print(result) + + +if __name__ == "__main__": + main() diff --git a/archive/p/python/prime_number.py b/archive/p/python/prime_number.py index cfd2b12b2..6e37fe57c 100644 --- a/archive/p/python/prime_number.py +++ b/archive/p/python/prime_number.py @@ -3,7 +3,7 @@ def is_prime(x): - if (x % 2 == 0 and x is not 2) or (x == 1): + if (x % 2 == 0 and x != 2) or (x == 1): return False return not bool([n for n in range(3, int(ceil(sqrt(x))+1)) if x % n == 0]) diff --git a/archive/p/python/testinfo.yml b/archive/p/python/testinfo.yml index 97398472b..9e4f8009f 100644 --- a/archive/p/python/testinfo.yml +++ b/archive/p/python/testinfo.yml @@ -4,5 +4,5 @@ folder: container: image: "python" - tag: "3.7-alpine" + tag: "3.12-alpine" cmd: "python {{ source.name }}{{ source.extension }}" diff --git a/poetry.lock b/poetry.lock index 37d3e9de9..fdc40b323 100644 --- a/poetry.lock +++ b/poetry.lock @@ -279,14 +279,14 @@ test = ["coverage[toml]", "ddt (>=1.1.1,!=1.4.3)", "mock ; python_version < \"3. [[package]] name = "glotter2" -version = "0.10.1" +version = "0.10.2" description = "An execution library for scripts written in any language. This is a fork of https://github.com/auroq/glotter" optional = false python-versions = "<4.0,>=3.9" groups = ["main"] files = [ - {file = "glotter2-0.10.1-py3-none-any.whl", hash = "sha256:c9e3e818b68ec558c2a971574a7910ae46e86d48e7251524e5cf1bf90d0126d3"}, - {file = "glotter2-0.10.1.tar.gz", hash = "sha256:d9bd8ed341dceb77e4d995b9bcdbf8ded226916727d228bf8ad460d340f58900"}, + {file = "glotter2-0.10.2-py3-none-any.whl", hash = "sha256:e83546a52b0aa03a3fa1dca6a2e23c926b4b2c4b1e84b0fbf0ee680e9726bed2"}, + {file = "glotter2-0.10.2.tar.gz", hash = "sha256:ed6ddab1764a9f42320a25f1d98c2fd40c98d0a03237a55a7b155664ab4a13ba"}, ] [package.dependencies] @@ -838,4 +838,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" python-versions = ">=3.9,<4.0" -content-hash = "c635f51c20ddff22b02366c66adaf986844134195fb660e32347cb48674194a1" +content-hash = "010bca7dafa656d2159f06e5d6d05ffd58007dc11bc0356d6de86917338455f1" diff --git a/pyproject.toml b/pyproject.toml index 0efd892c4..720d977a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ license = "MIT" dependencies = [ "ronbun (>=0.9.0,<0.10.0)", - "glotter2 (>=0.10.1,<0.11.0)" + "glotter2 (>=0.10.2,<0.11.0)" ] # Initiator of the collection @@ -32,5 +32,7 @@ maintainers = [ [tool.poetry] package-mode = false +[tool.poetry.dependencies] +glotter2 = {develop = true} [tool.pytest.ini_options] console_output_style = "count"