From 208dec7705a449a90a2cb7402bbcab326a7e41e7 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Wed, 8 Jul 2020 19:38:19 +0200 Subject: [PATCH] ngf fix --- CONTRIBUTIONS.md | 2 +- katrain/core/sgf_parser.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTIONS.md b/CONTRIBUTIONS.md index cca2da7..a53af0d 100644 --- a/CONTRIBUTIONS.md +++ b/CONTRIBUTIONS.md @@ -48,7 +48,7 @@ Many thanks to these additional authors: * "nowoowoo" for a fix to the parser for SGF files with extra line breaks. * "nimets123" for the timer sound effects and board/stone graphics. * Jordan Seaward for the stone sound effects. -* "fohristiwhirl" for the Gibo format parsing code. +* "fohristiwhirl" for the Gibo and NGF formats parsing code. ## Translators diff --git a/katrain/core/sgf_parser.py b/katrain/core/sgf_parser.py index a10524c..1a259d1 100644 --- a/katrain/core/sgf_parser.py +++ b/katrain/core/sgf_parser.py @@ -338,14 +338,14 @@ class SGF: with open(filename, "rb") as f: bin_contents = f.read() if not encoding: - if not is_gib: + if is_gib or is_ngf: + encoding = "utf8" + else: # sgf match = re.search(rb"CA\[(.*?)\]", bin_contents) if match: encoding = match[1].decode("ascii", errors="ignore") else: encoding = "ISO-8859-1" # default - else: - encoding = "utf8" # ? decoded = bin_contents.decode(encoding=encoding, errors="ignore") if is_ngf: return cls.parse_ngf(decoded) @@ -431,7 +431,7 @@ class SGF: if handicap >= 2: root.set_property("HA", handicap) - root.place_handicap_stones(handicap, tygem=True) # While this isn't Tygem, it uses the same layout + root.place_handicap_stones(handicap, tygem=True) # While this isn't Tygem, it uses the same layout if komi: root.set_property("KM", komi) @@ -471,7 +471,7 @@ class SGF: node = cls._NODE_CLASS(parent=node) node.set_property(key, value) - if len(root.children) == 0: # We'll assume we failed in this case + if len(root.children) == 0: # We'll assume we failed in this case raise ParseError("Found no moves") return root