diff --git a/pyproject.toml b/pyproject.toml index 5b66302e74..93b6047edf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,7 +105,7 @@ quote-style = 'single' explicit-preview-rules = true ignore = [ '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', 'PLE1205', 'PLW0602', 'PLW0603', 'PLW1510', 'PLW1641', 'PLW2901', 'PLC0415', 'PLR0911', 'PLR0912', 'PLR0913', 'PLR0914', 'PLR0915', 'PLR0916', 'PLR0917', 'PLR1702', 'PLR1704', 'PLR2004', 'PLR6301', diff --git a/src/calibre/ebooks/lrf/html/color_map.py b/src/calibre/ebooks/lrf/html/color_map.py index 1fc4464256..132c36b931 100644 --- a/src/calibre/ebooks/lrf/html/color_map.py +++ b/src/calibre/ebooks/lrf/html/color_map.py @@ -107,7 +107,7 @@ def lrs_color(html_color): return '0x00'+match.group(1)+match.group(2)+match.group(3) match = rgb_pat.search(hcol) 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: return NAME_MAP[hcol].replace('#', '0x00') return '0x00000000' diff --git a/src/calibre/ebooks/mobi/debug/__init__.py b/src/calibre/ebooks/mobi/debug/__init__.py index 673178a74e..93d76df8a1 100644 --- a/src/calibre/ebooks/mobi/debug/__init__.py +++ b/src/calibre/ebooks/mobi/debug/__init__.py @@ -8,5 +8,5 @@ __docformat__ = 'restructuredtext en' def format_bytes(byts): byts = bytearray(byts) - byts = [hex(b)[2:] for b in byts] + byts = [f'{b:x}' for b in byts] return ' '.join(byts) diff --git a/src/calibre/ebooks/mobi/debug/headers.py b/src/calibre/ebooks/mobi/debug/headers.py index 041c04d64b..d98e44680e 100644 --- a/src/calibre/ebooks/mobi/debug/headers.py +++ b/src/calibre/ebooks/mobi/debug/headers.py @@ -461,7 +461,7 @@ class MOBIHeader: # {{{ a(f'Huffman record count: {self.huffman_record_count}') r('Huffman table offset', 'datp_record_offset') 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: a(f'Unknown3: {self.unknown3!r}') r('DRM Offset', 'drm_offset') diff --git a/src/calibre/ebooks/mobi/debug/mobi6.py b/src/calibre/ebooks/mobi/debug/mobi6.py index d4fe7dd44a..570f621e56 100644 --- a/src/calibre/ebooks/mobi/debug/mobi6.py +++ b/src/calibre/ebooks/mobi/debug/mobi6.py @@ -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}]') def bin4(num): - ans = bin(num)[2:] + ans = f'{num:b}' return as_bytes('0'*(4-len(ans)) + ans) def repr_extra(x): @@ -620,7 +620,7 @@ class TBSIndexing: # {{{ print(f'Failed to decode TBS bytes for record: {r.idx}') ans += a 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('') diff --git a/src/calibre/ebooks/mobi/reader/index.py b/src/calibre/ebooks/mobi/reader/index.py index 70af01b5e0..6a695914ef 100644 --- a/src/calibre/ebooks/mobi/reader/index.py +++ b/src/calibre/ebooks/mobi/reader/index.py @@ -39,7 +39,7 @@ class NotATAGXSection(InvalidFile): def format_bytes(byts): byts = bytearray(byts) - byts = [hex(b)[2:] for b in byts] + byts = [f'{b:x}' for b in byts] return ' '.join(byts) diff --git a/src/calibre/ebooks/mobi/utils.py b/src/calibre/ebooks/mobi/utils.py index 09be029b3d..15ea4b85cb 100644 --- a/src/calibre/ebooks/mobi/utils.py +++ b/src/calibre/ebooks/mobi/utils.py @@ -80,7 +80,7 @@ def encode_number_as_hex(num): The bytes that follow are simply the hexadecimal representation of the number. ''' - num = hex(num)[2:].upper().encode('ascii') + num = f'{num:X}'.encode('ascii') nlen = len(num) if nlen % 2 != 0: num = b'0'+num diff --git a/src/calibre/ebooks/pdf/render/fonts.py b/src/calibre/ebooks/pdf/render/fonts.py index dec0355783..d6bf5e1b4a 100644 --- a/src/calibre/ebooks/pdf/render/fonts.py +++ b/src/calibre/ebooks/pdf/render/fonts.py @@ -59,7 +59,7 @@ class FontStream(Stream): def to_hex_string(c): - ans = hex(int(c))[2:] + ans = f'{int(c):x}' if isinstance(ans, bytes): ans = ans.decode('ascii') return ans.rjust(4, '0')