Skip to content

Commit 3bcb7aa

Browse files
committed
Added a console script for an additional base encoding
1 parent a9c4bb9 commit 3bcb7aa

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

codext/base/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def _main():
209209
p.add_argument("--version", action="version")
210210
p.version = "CodExt " + __version__
211211
args = p.parse_args()
212+
if args.decode:
213+
args.wrap = 0
212214
args.invert = getattr(args, "invert", False)
213215
c, f = _input(args.file), [encode, decode][args.decode]
214216
c = c.rstrip("\r\n") if isinstance(c, str) else c.rstrip(b"\r\n")
@@ -217,7 +219,7 @@ def _main():
217219
except Exception as err:
218220
print("%sbase%s: invalid input" % (getattr(err, "output", ""), base))
219221
return 1
220-
for l in wrap(ensure_str(c), args.wrap):
222+
for l in (wrap(ensure_str(c), args.wrap) if args.wrap > 0 else [ensure_str(c)]):
221223
print(l)
222224
return 0
223225
return _main

codext/base/baseN.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
main16 = main(16, "RFC 4648")
3838

3939

40+
B26 = {'': upper, 'inv': lower}
41+
base(B26, r"^(?:base[-_]?26|hex)(|[-_]inv(?:erted)?)$")
42+
main26 = main(26)
43+
44+
4045
B32 = {
4146
r'': upper + "234567",
4247
r'[-_]inv(erted)?$': "234567" + upper,

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ console_scripts =
4949
base4 = codext.base.baseN:main4
5050
base8 = codext.base.baseN:main8
5151
base16 = codext.base.baseN:main16
52+
base26 = codext.base.baseN:main26
5253
base32 = codext.base.baseN:main32
5354
base32-hex = codext.base.baseN:main32hex
5455
base32-geohash = codext.base.baseN:main32geo

0 commit comments

Comments
 (0)