diff --git a/katrain/core/game_node.py b/katrain/core/game_node.py index 7572eaf..a2db1b7 100644 --- a/katrain/core/game_node.py +++ b/katrain/core/game_node.py @@ -138,8 +138,8 @@ class GameNode(SGFNode): *comments, f"\nSGF generated by {PROGRAM_NAME} {VERSION}{SGF_INTERNAL_COMMENTS_MARKER}\n", ] - properties["CA"] = "UTF-8" - properties["AP"] = f"{PROGRAM_NAME}:{VERSION}" + properties["CA"] = ["UTF-8"] + properties["AP"] = [f"{PROGRAM_NAME}:{VERSION}"] if self.shortcut_from: properties["KTSF"] = [id(self.shortcut_from)] elif "KTSF" in properties: diff --git a/katrain/core/sgf_parser.py b/katrain/core/sgf_parser.py index 8cdc2d5..a233d9f 100644 --- a/katrain/core/sgf_parser.py +++ b/katrain/core/sgf_parser.py @@ -326,6 +326,7 @@ class SGFNode: class SGF: + DEFAULT_ENCODING = "ISO-8859-1" # as specified by the standard _NODE_CLASS = SGFNode # Class used for SGF Nodes, can change this to something that inherits from SGFNode # https://xkcd.com/1171/ @@ -365,8 +366,11 @@ class SGF: if match: encoding = match[1].decode("ascii", errors="ignore") else: - encoding = "ISO-8859-1" # default - decoded = bin_contents.decode(encoding=encoding, errors="ignore") + encoding = cls.DEFAULT_ENCODING + try: + decoded = bin_contents.decode(encoding=encoding, errors="ignore") + except LookupError: + decoded = bin_contents.decode(encoding=cls.DEFAULT_ENCODING, errors="ignore") if is_ngf: return cls.parse_ngf(decoded) if is_gib: