fix encoding
This commit is contained in:
1 parent
70f91749e6
commit
03e93568c7
2 files changed
+8
-4
No files matched your search
@@ -138,8 +138,8 @@ class GameNode(SGFNode):
|
|||||||
*comments,
|
*comments,
|
||||||
f"\nSGF generated by {PROGRAM_NAME} {VERSION}{SGF_INTERNAL_COMMENTS_MARKER}\n",
|
f"\nSGF generated by {PROGRAM_NAME} {VERSION}{SGF_INTERNAL_COMMENTS_MARKER}\n",
|
||||||
]
|
]
|
||||||
properties["CA"] = "UTF-8"
|
properties["CA"] = ["UTF-8"]
|
||||||
properties["AP"] = f"{PROGRAM_NAME}:{VERSION}"
|
properties["AP"] = [f"{PROGRAM_NAME}:{VERSION}"]
|
||||||
if self.shortcut_from:
|
if self.shortcut_from:
|
||||||
properties["KTSF"] = [id(self.shortcut_from)]
|
properties["KTSF"] = [id(self.shortcut_from)]
|
||||||
elif "KTSF" in properties:
|
elif "KTSF" in properties:
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ class SGFNode:
|
|||||||
|
|
||||||
|
|
||||||
class SGF:
|
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
|
_NODE_CLASS = SGFNode # Class used for SGF Nodes, can change this to something that inherits from SGFNode
|
||||||
# https://xkcd.com/1171/
|
# https://xkcd.com/1171/
|
||||||
@@ -365,8 +366,11 @@ class SGF:
|
|||||||
if match:
|
if match:
|
||||||
encoding = match[1].decode("ascii", errors="ignore")
|
encoding = match[1].decode("ascii", errors="ignore")
|
||||||
else:
|
else:
|
||||||
encoding = "ISO-8859-1" # default
|
encoding = cls.DEFAULT_ENCODING
|
||||||
decoded = bin_contents.decode(encoding=encoding, errors="ignore")
|
try:
|
||||||
|
decoded = bin_contents.decode(encoding=encoding, errors="ignore")
|
||||||
|
except LookupError:
|
||||||
|
decoded = bin_contents.decode(encoding=cls.DEFAULT_ENCODING, errors="ignore")
|
||||||
if is_ngf:
|
if is_ngf:
|
||||||
return cls.parse_ngf(decoded)
|
return cls.parse_ngf(decoded)
|
||||||
if is_gib:
|
if is_gib:
|
||||||
|
|||||||
Reference in new issue
Block a user