mirror of
https://github.com/iKarith/cppo-ng.git
synced 2025-08-09 23:25:14 +00:00
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.
This commit is contained in:
@@ -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]
|
||||
|
Reference in New Issue
Block a user