Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
manuelseeger committed Jan 8, 2023
commit 99e1071a2bd69cd8e485caf2c7a44b3444fb7f9a
17 changes: 14 additions & 3 deletions sc2reader/scripts/sc2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sc2reader
from sc2reader.factories.plugins.replay import toJSON
import sys


def main():
Expand All @@ -15,6 +16,13 @@ def main():
default=None,
help="The per-line indent to use when printing a human readable json string",
)
parser.add_argument(
"--encoding",
"-e",
type=str,
default="UTF-8",
help="The character encoding use..",
)
parser.add_argument(
"path",
metavar="path",
Expand All @@ -25,9 +33,12 @@ def main():
args = parser.parse_args()

factory = sc2reader.factories.SC2Factory()
try:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change above is good.
The change below is not really required because the try / except block does the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I would leave the original try/except it would throw an AttributeError before the TypeError though if args.encoding doesn't exist

factory.register_plugin("Replay", toJSON(indent=args.indent))
except TypeError:

if sys.version_info.major < 3:
factory.register_plugin(
"Replay", toJSON(encoding=args.encoding, indent=args.indent)
) # legacy Python
else:
factory.register_plugin("Replay", toJSON(indent=args.indent))
replay_json = factory.load_replay(args.path[0])
print(replay_json)
Expand Down