mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-11-22 14:33:02 -05:00
f-string number format (manual)
ruff 'FURB116'
This commit is contained in:
parent
7bbdba14eb
commit
bf04a318bb
@ -105,7 +105,7 @@ quote-style = 'single'
|
|||||||
explicit-preview-rules = true
|
explicit-preview-rules = true
|
||||||
ignore = [
|
ignore = [
|
||||||
'E402', 'E741',
|
'E402', 'E741',
|
||||||
'UP012', 'UP030', 'C413', 'C420', 'PIE790', 'ISC003', 'FURB122', 'FURB166', 'FURB167', 'FURB116',
|
'UP012', 'UP030', 'C413', 'C420', 'PIE790', 'ISC003', 'FURB122', 'FURB166', 'FURB167',
|
||||||
'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF012', 'RUF013', 'RUF015', 'RUF031', 'RUF100',
|
'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF012', 'RUF013', 'RUF015', 'RUF031', 'RUF100',
|
||||||
'PLE1205', 'PLW0602', 'PLW0603', 'PLW1510', 'PLW1641', 'PLW2901', 'PLC0415',
|
'PLE1205', 'PLW0602', 'PLW0603', 'PLW1510', 'PLW1641', 'PLW2901', 'PLC0415',
|
||||||
'PLR0911', 'PLR0912', 'PLR0913', 'PLR0914', 'PLR0915', 'PLR0916', 'PLR0917', 'PLR1702', 'PLR1704', 'PLR2004', 'PLR6301',
|
'PLR0911', 'PLR0912', 'PLR0913', 'PLR0914', 'PLR0915', 'PLR0916', 'PLR0917', 'PLR1702', 'PLR1704', 'PLR2004', 'PLR6301',
|
||||||
|
|||||||
@ -107,7 +107,7 @@ def lrs_color(html_color):
|
|||||||
return '0x00'+match.group(1)+match.group(2)+match.group(3)
|
return '0x00'+match.group(1)+match.group(2)+match.group(3)
|
||||||
match = rgb_pat.search(hcol)
|
match = rgb_pat.search(hcol)
|
||||||
if match:
|
if match:
|
||||||
return '0x00'+hex(int(match.group(1)))[2:]+hex(int(match.group(2)))[2:]+hex(int(match.group(3)))[2:]
|
return f'0x00{int(match.group(1)):x}{int(match.group(2)):x}{int(match.group(3)):x}'
|
||||||
if hcol in NAME_MAP:
|
if hcol in NAME_MAP:
|
||||||
return NAME_MAP[hcol].replace('#', '0x00')
|
return NAME_MAP[hcol].replace('#', '0x00')
|
||||||
return '0x00000000'
|
return '0x00000000'
|
||||||
|
|||||||
@ -8,5 +8,5 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
def format_bytes(byts):
|
def format_bytes(byts):
|
||||||
byts = bytearray(byts)
|
byts = bytearray(byts)
|
||||||
byts = [hex(b)[2:] for b in byts]
|
byts = [f'{b:x}' for b in byts]
|
||||||
return ' '.join(byts)
|
return ' '.join(byts)
|
||||||
|
|||||||
@ -461,7 +461,7 @@ class MOBIHeader: # {{{
|
|||||||
a(f'Huffman record count: {self.huffman_record_count}')
|
a(f'Huffman record count: {self.huffman_record_count}')
|
||||||
r('Huffman table offset', 'datp_record_offset')
|
r('Huffman table offset', 'datp_record_offset')
|
||||||
a(f'Huffman table length: {self.datp_record_count!r}')
|
a(f'Huffman table length: {self.datp_record_count!r}')
|
||||||
a(f'EXTH flags: {bin(self.exth_flags)[2:]} ({self.has_exth})')
|
a(f'EXTH flags: {self.exth_flags:b} ({self.has_exth})')
|
||||||
if self.has_drm_data:
|
if self.has_drm_data:
|
||||||
a(f'Unknown3: {self.unknown3!r}')
|
a(f'Unknown3: {self.unknown3!r}')
|
||||||
r('DRM Offset', 'drm_offset')
|
r('DRM Offset', 'drm_offset')
|
||||||
|
|||||||
@ -593,7 +593,7 @@ class TBSIndexing: # {{{
|
|||||||
ans.append(f'\t\tIndex Entry: {x.index} (Parent index: {x.parent_index}, Depth: {x.depth}, Offset: {x.offset}, Size: {x.size}) [{x.label}]')
|
ans.append(f'\t\tIndex Entry: {x.index} (Parent index: {x.parent_index}, Depth: {x.depth}, Offset: {x.offset}, Size: {x.size}) [{x.label}]')
|
||||||
|
|
||||||
def bin4(num):
|
def bin4(num):
|
||||||
ans = bin(num)[2:]
|
ans = f'{num:b}'
|
||||||
return as_bytes('0'*(4-len(ans)) + ans)
|
return as_bytes('0'*(4-len(ans)) + ans)
|
||||||
|
|
||||||
def repr_extra(x):
|
def repr_extra(x):
|
||||||
@ -620,7 +620,7 @@ class TBSIndexing: # {{{
|
|||||||
print(f'Failed to decode TBS bytes for record: {r.idx}')
|
print(f'Failed to decode TBS bytes for record: {r.idx}')
|
||||||
ans += a
|
ans += a
|
||||||
if byts:
|
if byts:
|
||||||
sbyts = tuple(hex(b)[2:] for b in byts)
|
sbyts = tuple(f'{b:x}' for b in byts)
|
||||||
ans.append('Remaining bytes: {}'.format(' '.join(sbyts)))
|
ans.append('Remaining bytes: {}'.format(' '.join(sbyts)))
|
||||||
|
|
||||||
ans.append('')
|
ans.append('')
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class NotATAGXSection(InvalidFile):
|
|||||||
|
|
||||||
def format_bytes(byts):
|
def format_bytes(byts):
|
||||||
byts = bytearray(byts)
|
byts = bytearray(byts)
|
||||||
byts = [hex(b)[2:] for b in byts]
|
byts = [f'{b:x}' for b in byts]
|
||||||
return ' '.join(byts)
|
return ' '.join(byts)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,7 @@ def encode_number_as_hex(num):
|
|||||||
The bytes that follow are simply the hexadecimal representation of the
|
The bytes that follow are simply the hexadecimal representation of the
|
||||||
number.
|
number.
|
||||||
'''
|
'''
|
||||||
num = hex(num)[2:].upper().encode('ascii')
|
num = f'{num:X}'.encode('ascii')
|
||||||
nlen = len(num)
|
nlen = len(num)
|
||||||
if nlen % 2 != 0:
|
if nlen % 2 != 0:
|
||||||
num = b'0'+num
|
num = b'0'+num
|
||||||
|
|||||||
@ -59,7 +59,7 @@ class FontStream(Stream):
|
|||||||
|
|
||||||
|
|
||||||
def to_hex_string(c):
|
def to_hex_string(c):
|
||||||
ans = hex(int(c))[2:]
|
ans = f'{int(c):x}'
|
||||||
if isinstance(ans, bytes):
|
if isinstance(ans, bytes):
|
||||||
ans = ans.decode('ascii')
|
ans = ans.decode('ascii')
|
||||||
return ans.rjust(4, '0')
|
return ans.rjust(4, '0')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user