Skip to content

Commit 351fa75

Browse files
committed
Applied minor improvements
1 parent 8edf475 commit 351fa75

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

codext/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ def main():
9898
guess.add_argument("encoding", nargs="*", help="list of known encodings to apply (default: none)")
9999
guess.add_argument("-c", "--codec-categories", nargs="*", help="codec categories to be included in the search ; "
100100
"format: string|tuple")
101+
guess.add_argument("-d", "--min-depth", default=0, type=int, help="minimum codec search depth before triggering "
102+
"results (default: 0)")
103+
guess.add_argument("-D", "--max-depth", default=5, type=int, help="maximum codec search depth (default: 5)")
101104
guess.add_argument("-e", "--exclude-codecs", nargs="*", help="codecs to be explicitely not used ; "
102105
"format: string|tuple")
103-
guess.add_argument("-f", "--stop-function", default="text", help="result checking function (default: text) ; "
104-
"format: printables|text|flag|lang_[bigram]|[regex]")
105-
guess.add_argument("--max-depth", default=5, type=int, help="maximum codec search depth (default: 5)")
106-
guess.add_argument("--min-depth", default=0, type=int, help="minimum codec search depth before triggering results "
107-
"(default: 0)")
108-
guess.add_argument("--extended", action="store_true",
106+
guess.add_argument("-E", "--extended", action="store_true",
109107
help="while using the scoring heuristic, also consider null scores (default: False)")
110-
guess.add_argument("--no-heuristic", action="store_true", help="do not use the scoring heuristic (default: False)")
108+
lng = "lang_%s" % LANG
109+
def_func = lng if getattr(stopfunc, lng, None) else "text"
110+
guess.add_argument("-f", "--stop-function", default=def_func, help="result checking function (default: %s) ; "
111+
"format: printables|text|flag|lang_[bigram]|[regex]" % def_func)
112+
guess.add_argument("-H", "--heuristic", action="store_true", help="use the scoring heuristic for accelerating"
113+
" the search (default: False)")
111114
guess.add_argument("-s", "--do-not-stop", action="store_true",
112115
help="do not stop if a valid output is found (default: False)")
113116
guess.add_argument("-v", "--verbose", action="store_true",
@@ -117,9 +120,9 @@ def main():
117120
"format: string|tuple|list(strings|tuples)")
118121
rank.add_argument("-e", "--exclude-codecs", help="codecs to be explicitely not used ; "
119122
"format: string|tuple|list(strings|tuples)")
120-
rank.add_argument("-l", "--limit", type=int, default=10, help="limit the number of displayed results")
121-
rank.add_argument("--extended", action="store_true",
123+
rank.add_argument("-E", "--extended", action="store_true",
122124
help="while using the scoring heuristic, also consider null scores (default: False)")
125+
rank.add_argument("-l", "--limit", type=int, default=10, help="limit the number of displayed results")
123126
search = sparsers.add_parser("search", help="search for codecs")
124127
search.add_argument("pattern", nargs="+", help="encoding pattern to search")
125128
listi = sparsers.add_parser("list", help="list items")
@@ -198,7 +201,7 @@ def main():
198201
args.encoding,
199202
not args.do_not_stop,
200203
True, # show
201-
not args.no_heuristic,
204+
args.heuristic,
202205
args.extended,
203206
args.verbose)
204207
for i, o in enumerate(r.items()):

codext/base/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ def base(charset, pattern, pow2=False, encode_template=base_encode, decode_templ
128128
if pow2 and nb != int(nb):
129129
raise BaseError("Bad charset ; {} is not a power of 2".format(n))
130130

131-
def encode(param=""):
131+
def encode(param="", *args):
132132
a = _get_charset(charset, param)
133133
def _encode(input, errors="strict"):
134134
return encode_template(input, a, errors), len(input)
135135
return _encode
136136

137-
def decode(param=""):
137+
def decode(param="", *args):
138138
a = _get_charset(charset, param)
139139
sl, sc = "\n" not in a, "\n" not in a and not "\r" in a
140140
def _decode(input, errors="strict"):

codext/crypto/atbash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
"""Atbash Cipher Codec - atbash content encoding.
2+
"""Atbash Cipher Codec - atbash-based content encoding.
33
44
This codec:
55
- en/decodes strings from str to str

tests/test_common.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ def test_guess_decode(self):
150150
STR = "This is a test"
151151
self.assertEqual(STR, _l(codext.guess("VGhpcyBpcyBhIHRlc3Q=", "a test", max_depth=1)))
152152
self.assertEqual(STR, _l(codext.guess("CJG3Ix8bVcSRMLOqwDUg28aDsT7", "a test", found=["base62"])))
153-
if hasattr(codext.stopfunc, "lang_en"):
154-
f1, f2 = codext.stopfunc.lang_en, codext.stopfunc.lang_es
155-
self.assertEqual(STR, _l(codext.guess("CJG3Ix8bVcSRMLOqwDUg28aDsT7", f1, found=["base62"])))
156-
self.assertIsNotNone(_l(codext.guess("CJG3Ix8bVcSRMLOqwDUg28aDsT7", f1, max_depth=1)))
157-
self.assertNotEqual(STR, _l(codext.guess("CJG3Ix8bVcSRMLOqwDUg28aDsT7", f2, found=["base62"], max_depth=1)))
158153
self.assertEqual(STR, _l(codext.guess("VGhpcyBpcyBhIHRlc3Q=", "a test", 0, 1, "base", scoring_heuristic=True,
159154
exclude=["base100"])))
160155
self.assertEqual(STR, _l(codext.guess("VGhpcyBpcyBhIHRlc3Q=", "a test", 0, 1, ["base", "crypto"])))

0 commit comments

Comments
 (0)