mirror of
https://github.com/iKarith/cppo-ng.git
synced 2025-04-09 14:38:08 +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:
parent
5a39fcb647
commit
666ab4d578
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user