Skip to content

Commit 99e1071

Browse files
committed
Remove encoding option from JSON script.
Python3 deprecates encoding option on json.dumps and defaults to UTF8. The existing try didn't work since the plugin wrapper doesn't call json.dumps until after except statement in line 41.
1 parent 09a00cc commit 99e1071

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sc2reader/scripts/sc2json.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sc2reader
44
from sc2reader.factories.plugins.replay import toJSON
5+
import sys
56

67

78
def main():
@@ -15,6 +16,13 @@ def main():
1516
default=None,
1617
help="The per-line indent to use when printing a human readable json string",
1718
)
19+
parser.add_argument(
20+
"--encoding",
21+
"-e",
22+
type=str,
23+
default="UTF-8",
24+
help="The character encoding use..",
25+
)
1826
parser.add_argument(
1927
"path",
2028
metavar="path",
@@ -25,9 +33,12 @@ def main():
2533
args = parser.parse_args()
2634

2735
factory = sc2reader.factories.SC2Factory()
28-
try:
29-
factory.register_plugin("Replay", toJSON(indent=args.indent))
30-
except TypeError:
36+
37+
if sys.version_info.major < 3:
38+
factory.register_plugin(
39+
"Replay", toJSON(encoding=args.encoding, indent=args.indent)
40+
) # legacy Python
41+
else:
3142
factory.register_plugin("Replay", toJSON(indent=args.indent))
3243
replay_json = factory.load_replay(args.path[0])
3344
print(replay_json)

0 commit comments

Comments
 (0)