Skip to content

Commit 8af0cbd

Browse files
authored
feat: Support CP-932 for Windows (kyuridenamida#226)
1 parent 05dfbbc commit 8af0cbd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

atcodertools/executils/run_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import locale
23

34

45
def run_command(exec_cmd: str, current_working_dir: str) -> str:
@@ -7,4 +8,4 @@ def run_command(exec_cmd: str, current_working_dir: str) -> str:
78
stdout=subprocess.PIPE,
89
stderr=subprocess.STDOUT,
910
cwd=current_working_dir)
10-
return proc.stdout.decode("utf8")
11+
return proc.stdout.decode(locale.getpreferredencoding())

atcodertools/tools/submit.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ def main(prog, args, credential_supplier=None, use_local_session_cache=True) ->
110110
return False
111111

112112
code_path = args.code or os.path.join(args.dir, metadata.code_filename)
113-
with open(code_path, 'r') as f:
114-
source = f.read()
113+
for encoding in ['utf8', 'utf-8_sig', 'cp932']:
114+
try:
115+
with open(code_path, 'r', encoding=encoding) as f:
116+
source = f.read()
117+
break
118+
except UnicodeDecodeError:
119+
logger.warning("code wasn't recognized as {}".format(encoding))
115120
logger.info(
116121
"Submitting {} as {}".format(code_path, metadata.lang.name))
117122
submission = client.submit_source_code(

0 commit comments

Comments
 (0)