From aeac65b92afe5cb82632bb3f2ee006347b0b1bc5 Mon Sep 17 00:00:00 2001 From: Netherwhal Date: Fri, 14 Oct 2022 23:57:56 +0200 Subject: [PATCH] Fixes #144: use mutf8 --- .editorconfig | 12 ++++++++++++ .gitignore | 6 +++--- nbt/nbt.py | 6 ++++-- setup.py | 32 ++++++++++++++++---------------- 4 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..651815f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +indent_size = 2 +indent_style = space + +[*.py] +indent_size = 4 diff --git a/.gitignore b/.gitignore index 3cdb53d..e2a4f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -# Note: OS-specific or editor-specific config files should be set in a global ignore file. -# Use: git config --global core.excludesfile -*.pyc \ No newline at end of file +.DS_Store +/.idea/ +*.pyc diff --git a/nbt/nbt.py b/nbt/nbt.py index e727af6..7f6b5e3 100644 --- a/nbt/nbt.py +++ b/nbt/nbt.py @@ -13,6 +13,8 @@ from collections import MutableMapping, MutableSequence, Sequence import sys +import mutf8 + _PY3 = sys.version_info >= (3,) if _PY3: unicode = str @@ -360,10 +362,10 @@ def _parse_buffer(self, buffer): read = buffer.read(length.value) if len(read) != length.value: raise StructError() - self.value = read.decode("utf-8") + self.value = mutf8.decode_modified_utf8(read) def _render_buffer(self, buffer): - save_val = self.value.encode("utf-8") + save_val = mutf8.encode_modified_utf8(self.value) length = TAG_Short(len(save_val)) length._render_buffer(buffer) buffer.write(save_val) diff --git a/setup.py b/setup.py index e6a7cd5..9db29c8 100755 --- a/setup.py +++ b/setup.py @@ -4,27 +4,27 @@ from nbt import VERSION setup( - name = 'NBT', - version = ".".join(str(x) for x in VERSION), - description = 'Named Binary Tag Reader/Writer', - author = 'Thomas Woolford', - author_email = 'woolford.thomas@gmail.com', - url = 'http://github.com/twoolie/NBT', - license = open("LICENSE.txt").read(), - long_description = open("README.txt").read(), - packages = ['nbt'], - classifiers = [ + name='NBT', + version=".".join(str(x) for x in VERSION), + description='Named Binary Tag Reader/Writer', + author='Thomas Woolford', + author_email='woolford.thomas@gmail.com', + url='http://github.com/twoolie/NBT', + license=open("LICENSE.txt").read(), + long_description=open("README.txt").read(), + packages=['nbt'], + install_requires=['mutf8'], + classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Games/Entertainment", "Topic :: Software Development :: Libraries :: Python Modules" - ] + ] )