From 666ab4d5788181da7806797fc4351ec2637ac23c Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Thu, 13 Jul 2017 19:35:47 -0700 Subject: [PATCH] Remove to_bin as we have format() Python3 already has a means of turning numerical data into a binary string with format(). The only place it was used was with ProDOS case masks as it was, so it's an easy call to replace the specialty function with Python's internals. --- blocksfree/legacy.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/blocksfree/legacy.py b/blocksfree/legacy.py index d8fcf55..649f18a 100755 --- a/blocksfree/legacy.py +++ b/blocksfree/legacy.py @@ -223,7 +223,7 @@ def getCaseMask(arg1, arg2): if caseMaskDec < 32768: return None else: - return to_bin(caseMaskDec - 32768, 15) + return format(caseMaskDec - 32768, '015b') def getFileType(arg1, arg2): if g.src_shk: @@ -363,7 +363,7 @@ def getWorkingDirName(arg1, arg2=None): if caseMaskDec < 32768: caseMask = None else: - caseMask = to_bin(caseMaskDec - 32768,15) + caseMask = format(caseMaskDec - 32768,'015b') else: # subdirectory, get casemask from arg2 (not available in header) caseMask = arg2 if caseMask and not g.casefold_upper: @@ -812,18 +812,6 @@ def to_dec(val): else: raise Exception("to_dec() requires bytes, hex-ustr or [bin-ustr]") -def to_bin(val, fill = None): - """convert bytes, hex-ustr, or int/long to bin-ustr""" - if isinstance(val, bytes): # bytes - b = bin(to_dec(to_hex(val)))[2:] - elif isinstance(val, str): # hex-ustr - b = bin(int(val, 16))[2:] - elif isnumber(val): # int/long - b = bin(val)[2:] - else: - raise Exception("to_bin() requires bytes, hex-ustr, or int/long") - return b if not fill else b.zfill(fill) - def to_bytes(val): """converts hex-ustr, int/long, or [bin-ustr] to bytes""" if isinstance(val, list): # [bin-ustr]