Skip to content

Commit b186a96

Browse files
committed
Fixed bug in guess mode
1 parent a9ff116 commit b186a96

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

codext/__common__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,9 @@ def __develop(encodings):
12431243

12441244

12451245
def __guess(prev_input, input, stop_func, depth, max_depth, min_depth, codec_categories, exclude, result, found=(),
1246-
stop=True, show=False, scoring_heuristic=False, extended=False, debug=False, regex=False):
1246+
stop=True, show=False, scoring_heuristic=False, extended=False, debug=False):
12471247
""" Perform a breadth-first tree search using a ranking logic to select and prune the list of codecs. """
12481248
if depth > min_depth and stop_func(input):
1249-
if regex:
1250-
stop = True
12511249
if not stop and (show or debug) and found not in result:
12521250
s = repr(input)
12531251
s = s[2:-1] if s.startswith("b'") and s.endswith("'") else s
@@ -1288,7 +1286,7 @@ def expand(items, descr=None, transform=None):
12881286
if debug:
12891287
print("[*] Depth %0{}d/%d: %s".format(len(str(max_depth))) % (depth+1, max_depth, encoding))
12901288
__guess(input, new_input, stop_func, depth+1, max_depth, min_depth, codec_categories, exclude, result,
1291-
found + (encoding, ), stop, show, scoring_heuristic, extended, debug, regex)
1289+
found + (encoding, ), stop, show, scoring_heuristic, extended, debug)
12921290

12931291

12941292
def __rank(prev_input, input, prev_encoding, codecs, heuristic=False, extended=False, yield_score=False):
@@ -1371,8 +1369,8 @@ def __score(prev_input, input, prev_encoding, codec, heuristic=False, extended=F
13711369
expf = expf(f, encoding)
13721370
except TypeError:
13731371
expf = expf(f)
1374-
elif isinstance(expf, (int, float)):
1375-
epxf = f - .1 <= expf <= f + .1
1372+
if isinstance(expf, (int, float)):
1373+
expf = (f - .1 <= expf <= f + .1)
13761374
elif isinstance(expf, (tuple, list)) and len(expf) == 2:
13771375
expf = f - expf[1] <= expf[0] <= expf[1] + .1
13781376
s += [-1., .1][expf]
@@ -1414,17 +1412,15 @@ def guess(input, stop_func=stopfunc.default, min_depth=0, max_depth=5, codec_cat
14141412
if len(found) > 0:
14151413
for encoding in found:
14161414
input = decode(input, encoding)
1417-
regex = False
14181415
if isinstance(stop_func, string_types):
14191416
stop_func = stopfunc.regex(stop_func)
1420-
regex = True
14211417
result = {}
14221418
if len(input) > 0:
14231419
try:
14241420
# breadth-first search
14251421
for d in range(max_depth):
14261422
__guess("", input, stop_func, 0, d+1, min_depth, codec_categories, exclude, result, tuple(found), stop,
1427-
show, scoring_heuristic, extended, debug, regex)
1423+
show, scoring_heuristic, extended, debug)
14281424
if stop and len(result) > 0:
14291425
return result
14301426
except KeyboardInterrupt:

0 commit comments

Comments
 (0)