From 0843ab89e9307c21de0b02e003a5431b1839fcd2 Mon Sep 17 00:00:00 2001 From: Kaamkiya Date: Fri, 21 Feb 2025 21:54:26 -0500 Subject: [PATCH 1/6] feat: Add new project: base64 --- .glotter.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.glotter.yml b/.glotter.yml index 2f818124e..8ef24bf15 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -33,6 +33,35 @@ projects: - " *" transformations: - "splitlines" + base64: + words: + - "base64" + requires_parameters: true + tests: + base64_valid: + params: + - name: "sample input: lowercase string" + input: '"hello world"' + expected: "aGVsbG8gd29ybGQK" + - name: "sample input: long string" + input: '"They swam along the boat at incredible speeds."' + expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo=" + - name: "sample input: numbers" + input: '"1234567890"' + expected: "MTIzNDU2Nzg5MAo=" + - name: "sample input: symbols" + input: '123456789:;<=>?@[\]^_`{|}~!' + expected: "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K" + base64_invalid: + params: + - name: "no input" + input: null + expected: "Usage: please provide a string to encode" + - name: "empty input" + input: '""' + expected: "Usage: please provide a string to encode" + transformations: + - "strip" binarysearch: words: - "binary" From 5374365cafd5914a1a99a15a19a93d152e43e80c Mon Sep 17 00:00:00 2001 From: Kaamkiya Date: Sat, 22 Feb 2025 09:29:35 -0500 Subject: [PATCH 2/6] chore: Add more tests, and decoding --- .glotter.yml | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/.glotter.yml b/.glotter.yml index 8ef24bf15..52e31aaaa 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -40,26 +40,53 @@ projects: tests: base64_valid: params: - - name: "sample input: lowercase string" - input: '"hello world"' + - name: "encode: lowercase string" + input: '"encode" "hello world"' expected: "aGVsbG8gd29ybGQK" - - name: "sample input: long string" - input: '"They swam along the boat at incredible speeds."' + - name: "encode: long string" + input: '"encode" "They swam along the boat at incredible speeds."' expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo=" - - name: "sample input: numbers" - input: '"1234567890"' + - name: "encode: numbers" + input: '"encode" "1234567890"' expected: "MTIzNDU2Nzg5MAo=" - - name: "sample input: symbols" - input: '123456789:;<=>?@[\]^_`{|}~!' + - name: "encode: symbols" + input: '"encode" "123456789:;<=>?@[]^_`{|}~!""' expected: "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K" + - name: "decode: lowercase string" + input: '"decode" "aGVsbG8gd29ybGQK"' + expected: "hello world" + - name: "decode: long string" + input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo="' + input: "They swam along the boat at incredible speeds." + - name: "decode: numbers" + expected: '"decode" "MTIzNDU2Nzg5MAo="' + input: "1234567890" + - name: "decode: symbols" + input: '"decode" "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K"' + expected: '123456789:;<=>?@[\]^_`{|}~!' base64_invalid: params: - name: "no input" input: null - expected: "Usage: please provide a string to encode" + expected: "Usage: please provide a mode and a string to encode/decode" - name: "empty input" - input: '""' - expected: "Usage: please provide a string to encode" + input: '"" ""' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "missing mode" + input: '"" "Goodbye, Mars"' + 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" + - name: "empty string" + input: '"decode" ""' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "missing string" + input: '"encode"' + expected: "Usage: please provide a mode and a string to encode/decode" + - name: "invalid encoded string" + input: '"decode" "hello world"' + expected: "Usage: please provide a mode and a string to encode/decode" transformations: - "strip" binarysearch: From b09ee587116a69158bbf6d2bed5af2027e64d81a Mon Sep 17 00:00:00 2001 From: Kaamkiya Date: Sat, 22 Feb 2025 09:34:03 -0500 Subject: [PATCH 3/6] fix: input -> expected --- .glotter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.glotter.yml b/.glotter.yml index 52e31aaaa..b1459f592 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -57,7 +57,7 @@ projects: expected: "hello world" - name: "decode: long string" input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo="' - input: "They swam along the boat at incredible speeds." + expected: "They swam along the boat at incredible speeds." - name: "decode: numbers" expected: '"decode" "MTIzNDU2Nzg5MAo="' input: "1234567890" From 84a219103a9340032bd0dc1f5674c1a7de908eda Mon Sep 17 00:00:00 2001 From: Zia Date: Sat, 22 Feb 2025 11:02:15 -0500 Subject: [PATCH 4/6] fix: Add transformations for valid tests --- .glotter.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.glotter.yml b/.glotter.yml index b1459f592..040ad912a 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -64,6 +64,8 @@ projects: - name: "decode: symbols" input: '"decode" "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K"' expected: '123456789:;<=>?@[\]^_`{|}~!' + transformations: + - "strip" base64_invalid: params: - name: "no input" From 1dc7df3296d18c250e16425521ab6fbd1433fd51 Mon Sep 17 00:00:00 2001 From: Kaamkiya Date: Sat, 22 Feb 2025 13:47:49 -0500 Subject: [PATCH 5/6] fix: Remove trailing newlines --- .glotter.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.glotter.yml b/.glotter.yml index 040ad912a..c3dbae449 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -42,27 +42,27 @@ projects: params: - name: "encode: lowercase string" input: '"encode" "hello world"' - expected: "aGVsbG8gd29ybGQK" + expected: "aGVsbG8gd29ybGQ=" - name: "encode: long string" input: '"encode" "They swam along the boat at incredible speeds."' - expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo=" + expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg==" - name: "encode: numbers" input: '"encode" "1234567890"' - expected: "MTIzNDU2Nzg5MAo=" + expected: "MTIzNDU2Nzg5MA==" - name: "encode: symbols" - input: '"encode" "123456789:;<=>?@[]^_`{|}~!""' - expected: "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K" + input: '"encode" "123456789:;<=>?@[]^_`{|}~!"' + expected: "MTIzNDU2Nzg5Ojs8PT4/QFtdXl9ge3x9fiEi" - name: "decode: lowercase string" - input: '"decode" "aGVsbG8gd29ybGQK"' + input: '"decode" "aGVsbG8gd29ybGQ="' expected: "hello world" - name: "decode: long string" - input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLgo="' + input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg=="' expected: "They swam along the boat at incredible speeds." - name: "decode: numbers" - expected: '"decode" "MTIzNDU2Nzg5MAo="' + expected: '"decode" "MTIzNDU2Nzg5MA=="' input: "1234567890" - name: "decode: symbols" - input: '"decode" "MTIzNDU2Nzg5Ojs8PT4/QFtcXV5fYHt8fX4K"' + input: '"decode" "MTIzNDU2Nzg5Ojs8PT4/QFtdXl9ge3x9fiEi"' expected: '123456789:;<=>?@[\]^_`{|}~!' transformations: - "strip" From 22091638ec53ba21c35543ee34ca6413c6210d95 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Sat, 22 Mar 2025 12:57:09 -0500 Subject: [PATCH 6/6] Rename to base64_encode_decode, reorganize tests, upgrade python, and add sample --- .glotter.yml | 84 ++++++++++++++++-------- archive/p/python/base64_encode_decode.py | 40 +++++++++++ archive/p/python/prime_number.py | 2 +- archive/p/python/testinfo.yml | 2 +- poetry.lock | 8 +-- pyproject.toml | 4 +- 6 files changed, 106 insertions(+), 34 deletions(-) create mode 100644 archive/p/python/base64_encode_decode.py diff --git a/.glotter.yml b/.glotter.yml index c3dbae449..85b4ed937 100644 --- a/.glotter.yml +++ b/.glotter.yml @@ -33,61 +33,91 @@ projects: - " *" transformations: - "splitlines" - base64: + base64_encode_decode: words: - "base64" + - "encode" + - "decode" requires_parameters: true tests: - base64_valid: + base64_encode_valid: params: - - name: "encode: lowercase string" + - name: "lowercase string" input: '"encode" "hello world"' expected: "aGVsbG8gd29ybGQ=" - - name: "encode: long string" + - name: "long string" input: '"encode" "They swam along the boat at incredible speeds."' expected: "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg==" - - name: "encode: numbers" + - name: "numbers" input: '"encode" "1234567890"' expected: "MTIzNDU2Nzg5MA==" - - name: "encode: symbols" - input: '"encode" "123456789:;<=>?@[]^_`{|}~!"' - expected: "MTIzNDU2Nzg5Ojs8PT4/QFtdXl9ge3x9fiEi" - - name: "decode: lowercase string" + - 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: "decode: long string" + - name: "long string" input: '"decode" "VGhleSBzd2FtIGFsb25nIHRoZSBib2F0IGF0IGluY3JlZGlibGUgc3BlZWRzLg=="' expected: "They swam along the boat at incredible speeds." - - name: "decode: numbers" - expected: '"decode" "MTIzNDU2Nzg5MA=="' - input: "1234567890" - - name: "decode: symbols" - input: '"decode" "MTIzNDU2Nzg5Ojs8PT4/QFtdXl9ge3x9fiEi"' - expected: '123456789:;<=>?@[\]^_`{|}~!' + - 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: + base64_invalid_inputs: params: - name: "no input" input: null expected: "Usage: please provide a mode and a string to encode/decode" - - name: "empty input" - input: '"" ""' - expected: "Usage: please provide a mode and a string to encode/decode" - - name: "missing mode" - input: '"" "Goodbye, Mars"' - 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: '"decode" ""' + input: '"encode" ""' expected: "Usage: please provide a mode and a string to encode/decode" + transformations: + - "strip" + base64_invalid_decode: + params: - name: "missing string" - input: '"encode"' + 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: "invalid encoded string" - input: '"decode" "hello world"' + - name: "pad characters in middle" + input: '"decode" "MTIzNDU2=Nzg5M=="' expected: "Usage: please provide a mode and a string to encode/decode" transformations: - "strip" 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"