Fix BrokenPipeError when piping kbinxml output

This commit is contained in:
William Toohey 2024-04-28 10:54:05 +10:00
parent b1cb927fd2
commit 1b6a3580cc
2 changed files with 12 additions and 9 deletions

View File

@ -1,14 +1,14 @@
import argparse
from struct import calcsize
import sys
import operator
import sys
from io import BytesIO
from struct import calcsize
import lxml.etree as etree
from .bytebuffer import ByteBuffer
from .sixbit import pack_sixbit, unpack_sixbit
from .format_ids import xml_formats, xml_types
from .sixbit import pack_sixbit, unpack_sixbit
DEBUG_OFFSETS = False
DEBUG = False
@ -479,10 +479,14 @@ def main():
xml = KBinXML(input, convert_illegal_things=args.convert_illegal)
stdout = getattr(sys.stdout, "buffer", sys.stdout)
if KBinXML.is_binary_xml(input):
stdout.write(xml.to_text().encode("utf-8"))
else:
stdout.write(xml.to_binary())
try:
if KBinXML.is_binary_xml(input):
stdout.write(xml.to_text().encode("utf-8"))
else:
stdout.write(xml.to_binary())
except BrokenPipeError:
# allows kbinxml to be piped to `head` or similar
sys.exit(141)
if __name__ == "__main__":

View File

@ -1,13 +1,12 @@
from setuptools import setup
requires = [
"lxml",
]
python_requires = ">=3.10"
version = "2.0"
version = "2.1"
setup(
name="kbinxml",
description="Decoder/encoder for Konami's binary XML format",