Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Jan 10, 2025
1 parent fcff8c2 commit 144fc0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions py/LunaTranslator/cishu/mdict_/readmdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ def __init__(

#self._key_list = self._read_keys()

def __repr__(self):
return (
f"MDict({self._fname!r}, "
f"encoding={self._encoding!r}, "
f"passcode={self._passcode})"
)
# def __repr__(self):
# return (
# f"MDict({self._fname!r}, "
# f"encoding={self._encoding!r}, "
# f"passcode={self._passcode})"
# )

@property
def filename(self):
Expand Down Expand Up @@ -191,7 +191,7 @@ def _decode_block(self, block, decompressed_size):
+ data[encryption_size:]
)
else:
raise ValueError(f"encryption method {encryption_method} not supported")
raise ValueError("encryption method {} not supported".format(encryption_method))

# check adler checksum over decrypted data
if self._version >= 3:
Expand All @@ -206,7 +206,7 @@ def _decode_block(self, block, decompressed_size):
elif compression_method == 2:
decompressed_block = zlib.decompress(decrypted_block)
else:
raise ValueError(f"compression method {compression_method} not supported")
raise ValueError("compression method {} not supported".format(compression_method))

# check adler checksum over decompressed data
if self._version < 3:
Expand Down Expand Up @@ -438,7 +438,7 @@ def _read_keys_v3(self):
elif block_type == 0x04000000:
self._key_index_offset = block_offset
else:
raise RuntimeError(f"Unknown block type {block_type}")
raise RuntimeError("Unknown block type {}".format(block_type))
f.seek(block_size, 1)
# test the end of file
if f.read(4):
Expand Down Expand Up @@ -635,7 +635,6 @@ def _read_records_v1v2(self):
)
except zlib.error:
log.error("zlib decompress error")
log.debug(f"record_block_compressed = {record_block_compressed!r}")
continue
# split record block according to the offset info from key block
while i < len(self._key_list):
Expand Down Expand Up @@ -670,7 +669,6 @@ def read_records(self, index):
)
except zlib.error:
log.error("zlib decompress error")
log.debug(f"record_block_compressed = {record_block_compressed!r}")

# split record block according to the offset info from key block
data = record_block[
Expand Down Expand Up @@ -729,7 +727,7 @@ def _substitute_stylesheet(self, txt):
try:
style = self._stylesheet[key]
except KeyError:
log.error(f'invalid stylesheet key "{key}"')
log.error('invalid stylesheet key "{}"'.format(key))
continue
if p and p[-1] == "\n":
txt_styled = txt_styled + style[0] + p.rstrip() + style[1] + "\r\n"
Expand Down
4 changes: 2 additions & 2 deletions py/LunaTranslator/cishu/mdict_/ripemd128.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ def ripemd128(message: bytes) -> bytes:
return struct.pack("<LLLL", h0, h1, h2, h3)


def hexstr(bstr):
return "".join(f"{b:02x}" for b in bstr)
# def hexstr(bstr):
# return "".join(f"{b:02x}" for b in bstr)

0 comments on commit 144fc0f

Please sign in to comment.