From efc9f427e003f97c258a8aa82b6ce2d6de643ca5 Mon Sep 17 00:00:00 2001 From: Keenan Gugeler Date: Mon, 6 Sep 2021 17:57:19 -0400 Subject: [PATCH] add flake8-quotes and fix quoting issues --- .github/workflows/build.yml | 2 +- dmoj/checkers/identical.py | 2 +- dmoj/checkers/linecount.py | 2 +- dmoj/cli.py | 4 ++-- dmoj/commands/submissions.py | 2 +- dmoj/commands/submit.py | 2 +- dmoj/commands/test.py | 2 +- dmoj/cptbox/syscalls/generate_linux.py | 4 ++-- dmoj/error.py | 2 +- dmoj/executors/ADA.py | 4 ++-- dmoj/executors/BF.py | 4 ++-- dmoj/executors/C.py | 4 ++-- dmoj/executors/C11.py | 4 ++-- dmoj/executors/CBL.py | 4 ++-- dmoj/executors/COFFEE.py | 4 ++-- dmoj/executors/CPP03.py | 4 ++-- dmoj/executors/CPP11.py | 4 ++-- dmoj/executors/CPP14.py | 4 ++-- dmoj/executors/CPP17.py | 4 ++-- dmoj/executors/CPP20.py | 4 ++-- dmoj/executors/D.py | 4 ++-- dmoj/executors/DART.py | 4 ++-- dmoj/executors/F95.py | 4 ++-- dmoj/executors/FORTH.py | 4 ++-- dmoj/executors/GAS32.py | 4 ++-- dmoj/executors/GAS64.py | 4 ++-- dmoj/executors/GASARM.py | 4 ++-- dmoj/executors/GO.py | 4 ++-- dmoj/executors/GROOVY.py | 4 ++-- dmoj/executors/HASK.py | 4 ++-- dmoj/executors/ICK.py | 4 ++-- dmoj/executors/JAVA10.py | 4 ++-- dmoj/executors/JAVA11.py | 4 ++-- dmoj/executors/JAVA8.py | 4 ++-- dmoj/executors/JAVA9.py | 4 ++-- dmoj/executors/KOTLIN.py | 4 ++-- dmoj/executors/MONOCS.py | 4 ++-- dmoj/executors/MONOFS.py | 4 ++-- dmoj/executors/MONOVB.py | 4 ++-- dmoj/executors/NASM.py | 4 ++-- dmoj/executors/NASM64.py | 4 ++-- dmoj/executors/OBJC.py | 4 ++-- dmoj/executors/OCAML.py | 4 ++-- dmoj/executors/PAS.py | 4 ++-- dmoj/executors/PIKE.py | 4 ++-- dmoj/executors/PRO.py | 4 ++-- dmoj/executors/RKT.py | 4 ++-- dmoj/executors/RUST.py | 12 ++++++------ dmoj/executors/SBCL.py | 4 ++-- dmoj/executors/SCALA.py | 4 ++-- dmoj/executors/TCL.py | 4 ++-- dmoj/executors/TUR.py | 4 ++-- dmoj/executors/ZIG.py | 4 ++-- dmoj/executors/base_executor.py | 6 +++--- dmoj/executors/java_executor.py | 4 ++-- dmoj/executors/python_executor.py | 8 ++++---- dmoj/judge.py | 20 ++++++++++---------- dmoj/problem.py | 6 +++--- dmoj/tests/test_malformed_unicode.py | 4 ++-- dmoj/utils/os_ext.py | 8 ++++---- 60 files changed, 131 insertions(+), 131 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 334a18dca..32a3f4d0f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: python-version: 3.9 - name: Install Black and Flake8 run: | - pip install black==19.3b0 flake8 flake8-future-import flake8-logging-format flake8-import-order + pip install black==19.3b0 flake8 flake8-future-import flake8-logging-format flake8-import-order flake8-quotes - name: Run Flake8 run: | black --version diff --git a/dmoj/checkers/identical.py b/dmoj/checkers/identical.py index ea804b029..a0e1599f1 100644 --- a/dmoj/checkers/identical.py +++ b/dmoj/checkers/identical.py @@ -11,5 +11,5 @@ def check(process_output: bytes, judge_output: bytes, pe_allowed: bool = True, * feedback = None if pe_allowed and standard(utf8bytes(judge_output), utf8bytes(process_output)): # in the event the standard checker would have passed the problem, raise a presentation error - feedback = "Presentation Error, check your whitespace" + feedback = 'Presentation Error, check your whitespace' return CheckerResult(False, 0, feedback=feedback) diff --git a/dmoj/checkers/linecount.py b/dmoj/checkers/linecount.py index 9fc6e208a..cc2e6da62 100644 --- a/dmoj/checkers/linecount.py +++ b/dmoj/checkers/linecount.py @@ -4,7 +4,7 @@ from dmoj.result import CheckerResult from dmoj.utils.unicode import utf8bytes -verdict = u"\u2717\u2713" +verdict = u'\u2717\u2713' def check( diff --git a/dmoj/cli.py b/dmoj/cli.py index 3d5853010..a1dceaac7 100644 --- a/dmoj/cli.py +++ b/dmoj/cli.py @@ -114,7 +114,7 @@ def run_command(line): return cmd.execute(line[1:]) except InvalidCommandException as e: if e.message: - print_ansi("#ansi[%s](red|bold)\n" % e.message) + print_ansi('#ansi[%s](red|bold)\n' % e.message) print() return 1 else: @@ -129,7 +129,7 @@ def run_command(line): return run_command(judgeenv.cli_command) else: while True: - command = input(ansi_style("#ansi[dmoj](magenta)#ansi[>](green) ")).strip() + command = input(ansi_style('#ansi[dmoj](magenta)#ansi[>](green) ')).strip() run_command(shlex.split(command)) except (EOFError, KeyboardInterrupt): print() diff --git a/dmoj/commands/submissions.py b/dmoj/commands/submissions.py index ac7b1b3d8..e677f773d 100644 --- a/dmoj/commands/submissions.py +++ b/dmoj/commands/submissions.py @@ -16,7 +16,7 @@ def execute(self, line): args = self.arg_parser.parse_args(line) if args.limit is not None and args.limit <= 0: - raise InvalidCommandException("--limit must be >= 0") + raise InvalidCommandException('--limit must be >= 0') submissions = self.judge.graded_submissions if not args.limit else self.judge.graded_submissions[: args.limit] diff --git a/dmoj/commands/submit.py b/dmoj/commands/submit.py index 40e174edd..f8460db1a 100644 --- a/dmoj/commands/submit.py +++ b/dmoj/commands/submit.py @@ -59,7 +59,7 @@ def execute(self, line): ext = ext.upper() language_id = {'PY': 'PY2', 'CPP': 'CPP11', 'JAVA': 'JAVA8'}.get(ext, ext) else: - raise InvalidCommandException("no language is selected") + raise InvalidCommandException('no language is selected') elif language_id not in executors: raise InvalidCommandException("unknown language '%s'" % language_id) elif time_limit <= 0: diff --git a/dmoj/commands/test.py b/dmoj/commands/test.py index 7ae850a5f..85f12067e 100644 --- a/dmoj/commands/test.py +++ b/dmoj/commands/test.py @@ -79,7 +79,7 @@ def execute(self, line): map(lambda x: "'%s'" % x, filter(lambda problem_id: problem_id not in supported_problems, problem_ids)) ) if unknown_problems: - raise InvalidCommandException("unknown problem(s) %s" % unknown_problems) + raise InvalidCommandException('unknown problem(s) %s' % unknown_problems) tester = ProblemTester() total_fails = 0 diff --git a/dmoj/cptbox/syscalls/generate_linux.py b/dmoj/cptbox/syscalls/generate_linux.py index 451ae3244..5476432dc 100644 --- a/dmoj/cptbox/syscalls/generate_linux.py +++ b/dmoj/cptbox/syscalls/generate_linux.py @@ -99,14 +99,14 @@ with open('../syscalls.pyi', 'w') as interface: print( - '''\ + """\ from typing import List, Dict translator: List[List[int]] by_name: Dict[str, int] by_id: List[str] SYSCALL_COUNT: int -''', +""", file=interface, ) for name in sorted(names): diff --git a/dmoj/error.py b/dmoj/error.py index 76a34bab6..d06208223 100644 --- a/dmoj/error.py +++ b/dmoj/error.py @@ -12,7 +12,7 @@ class InternalError(Exception): class OutputLimitExceeded(Exception): def __init__(self, stream, limit): - super().__init__("exceeded %d-byte limit on %s stream" % (limit, stream)) + super().__init__('exceeded %d-byte limit on %s stream' % (limit, stream)) class InvalidCommandException(Exception): diff --git a/dmoj/executors/ADA.py b/dmoj/executors/ADA.py index 073ff6779..3290ca91f 100644 --- a/dmoj/executors/ADA.py +++ b/dmoj/executors/ADA.py @@ -5,13 +5,13 @@ class Executor(GCCExecutor): name = 'ADA' command = 'gnatmake' ext = 'adb' - test_program = '''\ + test_program = """\ with Ada.Text_IO; use Ada.Text_IO; procedure Hello is begin Put_Line ("echo: Hello, World!"); end Hello; -''' +""" @classmethod def get_version_flags(cls, command): diff --git a/dmoj/executors/BF.py b/dmoj/executors/BF.py index 5dcc5dc6c..95a8909b5 100644 --- a/dmoj/executors/BF.py +++ b/dmoj/executors/BF.py @@ -4,7 +4,7 @@ from dmoj.error import CompileError from dmoj.executors.C import Executor as CExecutor -template = b'''\ +template = b"""\ #define _GNU_SOURCE #include #include @@ -29,7 +29,7 @@ {code} } -''' +""" trans = { ord('>'): b'++p;', diff --git a/dmoj/executors/C.py b/dmoj/executors/C.py index 5336506c5..91d53b0d1 100644 --- a/dmoj/executors/C.py +++ b/dmoj/executors/C.py @@ -6,7 +6,7 @@ class Executor(GCCExecutor): flags = ['-std=c99'] ext = 'c' name = 'C' - test_program = ''' + test_program = """ #include int main() { @@ -15,4 +15,4 @@ class Executor(GCCExecutor): putchar(ch); return 0; } -''' +""" diff --git a/dmoj/executors/C11.py b/dmoj/executors/C11.py index 6e347e2b9..ded596ecb 100644 --- a/dmoj/executors/C11.py +++ b/dmoj/executors/C11.py @@ -7,7 +7,7 @@ class Executor(GCCExecutor): command_paths = ['gcc'] ext = 'c' name = 'C11' - test_program = ''' + test_program = """ #include int main() { @@ -16,4 +16,4 @@ class Executor(GCCExecutor): putchar(ch); return 0; } -''' +""" diff --git a/dmoj/executors/CBL.py b/dmoj/executors/CBL.py index c56295667..98786f857 100644 --- a/dmoj/executors/CBL.py +++ b/dmoj/executors/CBL.py @@ -9,13 +9,13 @@ class Executor(CompiledExecutor): command = 'cobc' address_grace = 131072 compile_output_index = 0 - test_program = '''\ + test_program = """\ IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. PROCEDURE DIVISION. DISPLAY 'echo: Hello, World!'. STOP RUN. -''' # noqa: W191 +""" # noqa: W191 def get_compile_args(self): return [self.get_command(), '-x', '-free', self._code] diff --git a/dmoj/executors/COFFEE.py b/dmoj/executors/COFFEE.py index 090da03a9..88fb65225 100644 --- a/dmoj/executors/COFFEE.py +++ b/dmoj/executors/COFFEE.py @@ -20,12 +20,12 @@ class Executor(ScriptExecutor): 'eventfd2', 'statx', ] - test_program = '''\ + test_program = """\ process.stdin.on 'readable', () -> chunk = process.stdin.read() if chunk != null process.stdout.write chunk -''' +""" address_grace = 1048576 @classmethod diff --git a/dmoj/executors/CPP03.py b/dmoj/executors/CPP03.py index a89a2b4b7..8121971d1 100644 --- a/dmoj/executors/CPP03.py +++ b/dmoj/executors/CPP03.py @@ -8,14 +8,14 @@ class Executor(GCCExecutor): std: Optional[str] = None ext = 'cpp' name = 'CPP03' - test_program = ''' + test_program = """ #include int main() { std::cout << std::cin.rdbuf(); return 0; } -''' +""" def get_flags(self): return (['-std=%s' % self.std] if self.std else []) + super().get_flags() diff --git a/dmoj/executors/CPP11.py b/dmoj/executors/CPP11.py index 1b8766e03..87db5e3ac 100644 --- a/dmoj/executors/CPP11.py +++ b/dmoj/executors/CPP11.py @@ -6,7 +6,7 @@ class Executor(CPPExecutor): command_paths = ['g++-5', 'g++-4.9', 'g++-4.8', 'g++'] std = 'c++11' name = 'CPP11' - test_program = ''' + test_program = """ #include int main() { @@ -14,4 +14,4 @@ class Executor(CPPExecutor): std::cout << input; return 0; } -''' +""" diff --git a/dmoj/executors/CPP14.py b/dmoj/executors/CPP14.py index ac2623bc1..0df970d41 100644 --- a/dmoj/executors/CPP14.py +++ b/dmoj/executors/CPP14.py @@ -6,7 +6,7 @@ class Executor(CPPExecutor): command_paths = ['g++-5', 'g++'] std = 'c++14' name = 'CPP14' - test_program = ''' + test_program = """ #include auto input() { @@ -17,4 +17,4 @@ class Executor(CPPExecutor): std::cout << input(); return 0; } -''' +""" diff --git a/dmoj/executors/CPP17.py b/dmoj/executors/CPP17.py index e5618d32d..415aafcb1 100644 --- a/dmoj/executors/CPP17.py +++ b/dmoj/executors/CPP17.py @@ -6,7 +6,7 @@ class Executor(CPPExecutor): command_paths = ['g++-7', 'g++'] std = 'c++17' name = 'CPP17' - test_program = ''' + test_program = """ #include int main() { @@ -15,4 +15,4 @@ class Executor(CPPExecutor): std::cout << input; return 0; } -''' +""" diff --git a/dmoj/executors/CPP20.py b/dmoj/executors/CPP20.py index ff60ececd..c5ffc0278 100644 --- a/dmoj/executors/CPP20.py +++ b/dmoj/executors/CPP20.py @@ -6,7 +6,7 @@ class Executor(CPPExecutor): command_paths = ['g++-11', 'g++'] std = 'c++20' name = 'CPP20' - test_program = ''' + test_program = """ #include int main() { @@ -15,4 +15,4 @@ class Executor(CPPExecutor): std::cout << input; return 0; } -''' +""" diff --git a/dmoj/executors/D.py b/dmoj/executors/D.py index 4e968859d..481ec6df1 100644 --- a/dmoj/executors/D.py +++ b/dmoj/executors/D.py @@ -6,13 +6,13 @@ class Executor(CompiledExecutor): name = 'D' address_grace = 32768 command = 'dmd' - test_program = '''\ + test_program = """\ import std.stdio; void main() { writeln(readln()); } -''' +""" source_filename_format = 'main.{ext}' def get_compile_args(self): diff --git a/dmoj/executors/DART.py b/dmoj/executors/DART.py index 3310626a6..8dbf5aa17 100644 --- a/dmoj/executors/DART.py +++ b/dmoj/executors/DART.py @@ -8,11 +8,11 @@ class Executor(CompiledExecutor): name = 'DART' nproc = -1 # Dart uses a really, really large number of threads command = 'dart' - test_program = ''' + test_program = """ void main() { print("echo: Hello, World!"); } -''' +""" address_grace = 128 * 1024 syscalls = ['epoll_create', 'epoll_ctl', 'epoll_wait', 'timerfd_settime', 'memfd_create', 'ftruncate'] diff --git a/dmoj/executors/F95.py b/dmoj/executors/F95.py index 13abfdf26..71e0d6f7c 100644 --- a/dmoj/executors/F95.py +++ b/dmoj/executors/F95.py @@ -5,9 +5,9 @@ class Executor(GCCExecutor): name = 'F95' command = 'gfortran' ext = 'f95' - test_program = '''\ + test_program = """\ character(100) :: line read(*,'(A)') line write(*,'(A)') line end -''' +""" diff --git a/dmoj/executors/FORTH.py b/dmoj/executors/FORTH.py index e1df148d5..cca1777de 100644 --- a/dmoj/executors/FORTH.py +++ b/dmoj/executors/FORTH.py @@ -5,11 +5,11 @@ class Executor(ScriptExecutor): name = 'FORTH' command = 'gforth' ext = 'fs' - test_program = '''\ + test_program = """\ : HELLO ( -- ) ." echo: Hello, World!" CR ; HELLO -''' +""" fs = [r'/\.gforth-history$'] def get_cmdline(self, **kwargs): diff --git a/dmoj/executors/GAS32.py b/dmoj/executors/GAS32.py index 80f2cdcaf..a4de945cb 100644 --- a/dmoj/executors/GAS32.py +++ b/dmoj/executors/GAS32.py @@ -5,7 +5,7 @@ class Executor(PlatformX86Mixin, GASExecutor): as_name = 'as_x86' name = 'GAS32' - test_program = r'''.intel_syntax noprefix + test_program = r""".intel_syntax noprefix .text .global _start @@ -35,4 +35,4 @@ class Executor(PlatformX86Mixin, GASExecutor): .bss buffer: .skip 4096 -''' # noqa: W191 +""" # noqa: W191 diff --git a/dmoj/executors/GAS64.py b/dmoj/executors/GAS64.py index 775f23269..cc96224b4 100644 --- a/dmoj/executors/GAS64.py +++ b/dmoj/executors/GAS64.py @@ -5,7 +5,7 @@ class Executor(PlatformX64Mixin, GASExecutor): as_name = 'as_x64' name = 'GAS64' - test_program = r'''.intel_syntax noprefix + test_program = r""".intel_syntax noprefix .text .global _start @@ -35,4 +35,4 @@ class Executor(PlatformX64Mixin, GASExecutor): .bss buffer: .skip 4096 -''' # noqa: W191 +""" # noqa: W191 diff --git a/dmoj/executors/GASARM.py b/dmoj/executors/GASARM.py index 5c76eca9b..daf61cdbf 100644 --- a/dmoj/executors/GASARM.py +++ b/dmoj/executors/GASARM.py @@ -15,7 +15,7 @@ class Executor(GASExecutor): crt_pre = env.runtime.crt_pre_arm or ['/usr/lib/arm-linux-gnueabihf/crt1.o', '/usr/lib/arm-linux-gnueabihf/crti.o'] crt_post = env.runtime.crt_post_arm or ['/usr/lib/arm-linux-gnueabihf/crtn.o'] name = 'GASARM' - test_program = r''' + test_program = r""" .global _start _start: mov r7, #4 @@ -28,4 +28,4 @@ class Executor(GASExecutor): .data string: .ascii "echo: Hello, World!\n" -''' +""" diff --git a/dmoj/executors/GO.py b/dmoj/executors/GO.py index 8101e0a75..ba3cd38d6 100644 --- a/dmoj/executors/GO.py +++ b/dmoj/executors/GO.py @@ -22,7 +22,7 @@ class Executor(CompiledExecutor): command = 'go' syscalls = ['mincore', 'epoll_create1', 'epoll_ctl', 'epoll_pwait', 'pselect6', 'mlock'] test_name = 'echo' - test_program = '''\ + test_program = """\ package main import "os" @@ -33,7 +33,7 @@ class Executor(CompiledExecutor): bio := bufio.NewReader(os.Stdin) text, _ := bio.ReadString(0) fmt.Print(text) -}''' +}""" def get_compile_env(self): return { diff --git a/dmoj/executors/GROOVY.py b/dmoj/executors/GROOVY.py index 88d600ee6..01e89ddb8 100644 --- a/dmoj/executors/GROOVY.py +++ b/dmoj/executors/GROOVY.py @@ -16,9 +16,9 @@ class Executor(JavaExecutor): vm = 'groovy_vm' security_policy = policy - test_program = '''\ + test_program = """\ println System.in.newReader().readLine() -''' +""" def create_files(self, problem_id, source_code, *args, **kwargs): super().create_files(problem_id, source_code, *args, **kwargs) diff --git a/dmoj/executors/HASK.py b/dmoj/executors/HASK.py index 0e2cb0ffb..2522f0e66 100644 --- a/dmoj/executors/HASK.py +++ b/dmoj/executors/HASK.py @@ -6,11 +6,11 @@ class Executor(NullStdoutMixin, CompiledExecutor): ext = 'hs' name = 'HASK' command = 'ghc' - test_program = '''\ + test_program = """\ main = do a <- getContents putStr a -''' +""" def get_compile_args(self): return [self.get_command(), '-O2', '-o', self.problem, self._code] diff --git a/dmoj/executors/ICK.py b/dmoj/executors/ICK.py index 7566d366f..5315d2c61 100644 --- a/dmoj/executors/ICK.py +++ b/dmoj/executors/ICK.py @@ -5,7 +5,7 @@ class Executor(CompiledExecutor): ext = 'i' name = 'ICK' command = 'ick' - test_program = '''\ + test_program = """\ PLEASE DO ,1 <- #1 DO .4 <- #0 DO .5 <- #0 @@ -28,7 +28,7 @@ class Executor(CompiledExecutor): DO .5 <- .2 DO ,1SUB#1 <- .3 (30) PLEASE READ OUT ,1 -''' +""" def get_compile_args(self): flags = [self.get_command(), '-O', self._code] diff --git a/dmoj/executors/JAVA10.py b/dmoj/executors/JAVA10.py index bd928529b..0cec509b2 100644 --- a/dmoj/executors/JAVA10.py +++ b/dmoj/executors/JAVA10.py @@ -7,7 +7,7 @@ class Executor(JavacExecutor): name = 'JAVA10' jvm_regex = r'java-10-|openjdk10' - test_program = '''\ + test_program = """\ import java.io.IOException; interface IORunnable { @@ -27,7 +27,7 @@ class Executor(JavacExecutor): System.out.write(buffer, 0, read); }); } -}''' +}""" def get_compile_args(self): return [self.get_compiler(), '-encoding', 'UTF-8', self._code] diff --git a/dmoj/executors/JAVA11.py b/dmoj/executors/JAVA11.py index e09fedbde..e82a2c5ff 100644 --- a/dmoj/executors/JAVA11.py +++ b/dmoj/executors/JAVA11.py @@ -7,7 +7,7 @@ class Executor(JavacExecutor): name = 'JAVA11' jvm_regex = r'java-11-|openjdk11' - test_program = '''\ + test_program = """\ import java.io.IOException; interface IORunnable { @@ -29,7 +29,7 @@ class Executor(JavacExecutor): System.out.write(buffer, 0, read); }); } -}''' +}""" def get_compile_args(self): return [self.get_compiler(), '-encoding', 'UTF-8', self._code] diff --git a/dmoj/executors/JAVA8.py b/dmoj/executors/JAVA8.py index 24355737d..93ba1f6a8 100644 --- a/dmoj/executors/JAVA8.py +++ b/dmoj/executors/JAVA8.py @@ -7,7 +7,7 @@ class Executor(JavacExecutor): name = 'JAVA8' jvm_regex = r'java-8-|jdk-8-|openjdk8|oracle-java8' - test_program = '''\ + test_program = """\ import java.io.IOException; interface IORunnable { @@ -27,7 +27,7 @@ class Executor(JavacExecutor): System.out.write(buffer, 0, read); }); } -}''' +}""" def get_compile_args(self): return [self.get_compiler(), '-encoding', 'UTF-8', '-profile', 'compact1', self._code] diff --git a/dmoj/executors/JAVA9.py b/dmoj/executors/JAVA9.py index 1067db132..5c575256a 100644 --- a/dmoj/executors/JAVA9.py +++ b/dmoj/executors/JAVA9.py @@ -7,7 +7,7 @@ class Executor(JavacExecutor): name = 'JAVA9' jvm_regex = r'java-9-|openjdk9|oracle-java9' - test_program = '''\ + test_program = """\ import java.io.IOException; interface IORunnable { @@ -27,7 +27,7 @@ class Executor(JavacExecutor): System.out.write(buffer, 0, read); }); } -}''' +}""" def get_compile_args(self): return [self.get_compiler(), '-encoding', 'UTF-8', self._code] diff --git a/dmoj/executors/KOTLIN.py b/dmoj/executors/KOTLIN.py index a6664dff0..f188d4b9a 100644 --- a/dmoj/executors/KOTLIN.py +++ b/dmoj/executors/KOTLIN.py @@ -15,11 +15,11 @@ class Executor(JavaExecutor): vm = 'kotlin_vm' security_policy = policy - test_program = '''\ + test_program = """\ fun main(args: Array) { println(readLine()) } -''' +""" def create_files(self, problem_id, source_code, *args, **kwargs): super().create_files(problem_id, source_code, *args, **kwargs) diff --git a/dmoj/executors/MONOCS.py b/dmoj/executors/MONOCS.py index a669ce50c..0198a87ef 100644 --- a/dmoj/executors/MONOCS.py +++ b/dmoj/executors/MONOCS.py @@ -7,7 +7,7 @@ class Executor(MonoExecutor): command = 'mono-csc' command_paths = ['mono-csc', 'mcs', 'dmcs', 'gmcs'] - test_program = '''\ + test_program = """\ using System; class test { @@ -16,7 +16,7 @@ class test { while (!string.IsNullOrEmpty(line = Console.ReadLine())) Console.WriteLine(line); } -}''' +}""" def get_compile_args(self): return [self.get_command(), self._code, '-r:System.Numerics.dll', '-out:%s' % self.get_compiled_file()] diff --git a/dmoj/executors/MONOFS.py b/dmoj/executors/MONOFS.py index 4f71685a1..d7cff692c 100644 --- a/dmoj/executors/MONOFS.py +++ b/dmoj/executors/MONOFS.py @@ -7,14 +7,14 @@ class Executor(MonoExecutor): command = 'fsharpc' compiler_time_limit = 20 - test_program = '''\ + test_program = """\ open System [] let main argv = Console.WriteLine(Console.ReadLine()) 0 -''' +""" def get_compile_args(self): return [ diff --git a/dmoj/executors/MONOVB.py b/dmoj/executors/MONOVB.py index f8789853b..bad1aeb45 100644 --- a/dmoj/executors/MONOVB.py +++ b/dmoj/executors/MONOVB.py @@ -9,7 +9,7 @@ class Executor(MonoExecutor): command = 'mono-vbnc' compile_output_index = 0 - test_program = '''\ + test_program = """\ Imports System Public Module modmain @@ -17,7 +17,7 @@ class Executor(MonoExecutor): Console.WriteLine(Console.ReadLine()) End Sub End Module -''' +""" def get_compile_args(self): return [self.get_command(), '/nologo', '/quiet', '/optimize+', '/out:%s' % self.get_compiled_file(), self._code] diff --git a/dmoj/executors/NASM.py b/dmoj/executors/NASM.py index b6d0cf2b2..2a9e7d685 100644 --- a/dmoj/executors/NASM.py +++ b/dmoj/executors/NASM.py @@ -6,7 +6,7 @@ class Executor(PlatformX86Mixin, NASMExecutor): name = 'NASM' - test_program = '''\ + test_program = """\ section .text global _start @@ -35,4 +35,4 @@ class Executor(PlatformX86Mixin, NASMExecutor): section .bss buffer resb 4096 -''' +""" diff --git a/dmoj/executors/NASM64.py b/dmoj/executors/NASM64.py index e2a031e97..2728ca157 100644 --- a/dmoj/executors/NASM64.py +++ b/dmoj/executors/NASM64.py @@ -6,7 +6,7 @@ class Executor(PlatformX64Mixin, NASMExecutor): name = 'NASM64' - test_program = '''\ + test_program = """\ section .text global _start @@ -34,4 +34,4 @@ class Executor(PlatformX64Mixin, NASMExecutor): section .bss buffer resb 4096 -''' +""" diff --git a/dmoj/executors/OBJC.py b/dmoj/executors/OBJC.py index 5c1de38b8..a4a26d0e6 100644 --- a/dmoj/executors/OBJC.py +++ b/dmoj/executors/OBJC.py @@ -14,7 +14,7 @@ class Executor(GCCExecutor): name = 'OBJC' address_grace = 131072 - test_program = r''' + test_program = r""" #import int main (int argc, const char * argv[]) { @@ -25,7 +25,7 @@ class Executor(GCCExecutor): [pool drain]; return 0; } -''' +""" def get_flags(self): return self.objc_flags + super().get_flags() diff --git a/dmoj/executors/OCAML.py b/dmoj/executors/OCAML.py index 60811fe76..742d47fe5 100644 --- a/dmoj/executors/OCAML.py +++ b/dmoj/executors/OCAML.py @@ -8,13 +8,13 @@ class Executor(CompiledExecutor): ext = 'ml' name = 'OCAML' command = 'ocamlfind' - test_program = ''' + test_program = """ open! Base open! Core open! Stdio let () = (In_channel.iter_lines Stdio.stdin ~f:print_endline) -''' +""" def get_compile_args(self): # fmt: off diff --git a/dmoj/executors/PAS.py b/dmoj/executors/PAS.py index 755a902e1..c120fdde2 100644 --- a/dmoj/executors/PAS.py +++ b/dmoj/executors/PAS.py @@ -6,13 +6,13 @@ class Executor(NullStdoutMixin, CompiledExecutor): ext = 'pas' name = 'PAS' command = 'fpc' - test_program = '''\ + test_program = """\ var line : string; begin readln(line); writeln(line); end. -''' +""" def get_compile_args(self): return [self.get_command(), '-Fe/dev/stderr', '-So', '-O2', self._code] diff --git a/dmoj/executors/PIKE.py b/dmoj/executors/PIKE.py index de625b95c..9e4bb023b 100644 --- a/dmoj/executors/PIKE.py +++ b/dmoj/executors/PIKE.py @@ -15,9 +15,9 @@ class Executor(ScriptExecutor): 'socketpair', ('fpathconf', ACCESS_EACCES), ] - test_program = '''\ + test_program = """\ int main() { write(Stdio.stdin.gets()); return 0; } -''' +""" diff --git a/dmoj/executors/PRO.py b/dmoj/executors/PRO.py index b2b004df0..576b8b3a8 100644 --- a/dmoj/executors/PRO.py +++ b/dmoj/executors/PRO.py @@ -5,7 +5,7 @@ class Executor(ScriptExecutor): ext = 'pl' name = 'PRO' command = 'swipl' - test_program = ''' + test_program = """ :- set_prolog_flag(verbose,silent). :- prompt(_, ''). :- use_module(library(readutil)). @@ -19,7 +19,7 @@ class Executor(ScriptExecutor): true. :- main. -''' +""" def get_cmdline(self, **kwargs): return [self.get_command(), '--goal=main', '-c', self._code] diff --git a/dmoj/executors/RKT.py b/dmoj/executors/RKT.py index 3df5ea458..1b4fbc027 100644 --- a/dmoj/executors/RKT.py +++ b/dmoj/executors/RKT.py @@ -17,10 +17,10 @@ class Executor(CompiledExecutor): data_grace = 4096 address_grace = 131072 - test_program = '''\ + test_program = """\ #lang racket (displayln (read-line)) -''' +""" def get_compile_args(self): return [self.runtime_dict['raco'], 'make', self._code] diff --git a/dmoj/executors/RUST.py b/dmoj/executors/RUST.py index 3f44fa9fd..81ee667f4 100644 --- a/dmoj/executors/RUST.py +++ b/dmoj/executors/RUST.py @@ -3,7 +3,7 @@ from dmoj.executors.compiled_executor import CompiledExecutor from dmoj.utils.os_ext import bool_env -CARGO_TOML = b'''\ +CARGO_TOML = b"""\ [package] name = "user_submission" version = "1.0.0" @@ -11,9 +11,9 @@ [dependencies] dmoj = "0.1" rand = "0.3" -''' +""" -CARGO_LOCK = b'''\ +CARGO_LOCK = b"""\ cargo-features = ["strip"] [root] @@ -59,16 +59,16 @@ "checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" "checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" -''' # noqa: E501 +""" # noqa: E501 -HELLO_WORLD_PROGRAM = '''\ +HELLO_WORLD_PROGRAM = """\ #[macro_use] extern crate dmoj; extern crate rand; fn main() { println!("echo: Hello, World!"); } -''' +""" class Executor(CompiledExecutor): diff --git a/dmoj/executors/SBCL.py b/dmoj/executors/SBCL.py index 0c2e14a06..4132c7d04 100644 --- a/dmoj/executors/SBCL.py +++ b/dmoj/executors/SBCL.py @@ -19,7 +19,7 @@ class Executor(NullStdoutMixin, CompiledExecutor): data_grace = 262144 nproc = -1 - compile_script = '''(compile-file "{code}")''' + compile_script = """(compile-file "{code}")""" def get_compile_args(self): return [self.get_command(), '--eval', self.compile_script.format(code=self._code), '--quit'] @@ -33,7 +33,7 @@ def get_cmdline(self, **kwargs): '--no-sysinit', '--no-userinit', '--load', - self.problem + ".fasl", + self.problem + '.fasl', '--quit', '--end-toplevel-options', ] diff --git a/dmoj/executors/SCALA.py b/dmoj/executors/SCALA.py index 9ced73fe5..d5991ff90 100644 --- a/dmoj/executors/SCALA.py +++ b/dmoj/executors/SCALA.py @@ -18,11 +18,11 @@ class Executor(JavaExecutor): vm = 'scala_vm' security_policy = policy - test_program = '''\ + test_program = """\ object self_test extends App { println("echo: Hello, World!") } -''' +""" def create_files(self, problem_id, source_code, *args, **kwargs): super().create_files(problem_id, source_code, *args, **kwargs) diff --git a/dmoj/executors/TCL.py b/dmoj/executors/TCL.py index 375b1bbcd..0339f13c6 100644 --- a/dmoj/executors/TCL.py +++ b/dmoj/executors/TCL.py @@ -10,10 +10,10 @@ class Executor(ScriptExecutor): address_grace = 131072 command = 'tclsh' syscalls = ['connect', 'access', 'getsockname'] - test_program = '''\ + test_program = """\ gets stdin input puts $input -''' +""" @classmethod def get_runtime_versions(cls): diff --git a/dmoj/executors/TUR.py b/dmoj/executors/TUR.py index 107d6e78c..2cd578031 100644 --- a/dmoj/executors/TUR.py +++ b/dmoj/executors/TUR.py @@ -8,11 +8,11 @@ class Executor(CompiledExecutor): ext = 't' name = 'TUR' command = 'tprolog' - test_program = '''\ + test_program = """\ var echo : string get echo : * put echo -''' +""" def get_fs(self): return super().get_fs() + [self._code + 'bc'] diff --git a/dmoj/executors/ZIG.py b/dmoj/executors/ZIG.py index 7388ba99b..958027442 100644 --- a/dmoj/executors/ZIG.py +++ b/dmoj/executors/ZIG.py @@ -6,7 +6,7 @@ class Executor(CompiledExecutor): name = 'ZIG' command = 'zig' compiler_time_limit = 30 - test_program = ''' + test_program = """ const std = @import("std"); pub fn main() !void { @@ -19,7 +19,7 @@ class Executor(CompiledExecutor): if (line.len == 0) break; try stdout.print("{}", .{line}); } -}''' +}""" def create_files(self, problem_id, source_code, *args, **kwargs): # This cleanup needs to happen because Zig refuses to compile carriage returns. diff --git a/dmoj/executors/base_executor.py b/dmoj/executors/base_executor.py index 711670e54..591106ebf 100644 --- a/dmoj/executors/base_executor.py +++ b/dmoj/executors/base_executor.py @@ -136,7 +136,7 @@ def run_self_test(cls, output: bool = True, error_callback: Optional[Callable[[A return True if output: - print_ansi("%-39s%s" % ('Self-testing #ansi[%s](|underline):' % cls.get_executor_name(), ''), end=' ') + print_ansi('%-39s%s' % ('Self-testing #ansi[%s](|underline):' % cls.get_executor_name(), ''), end=' ') try: executor = cls(cls.test_name, utf8bytes(cls.test_program)) proc = executor.launch( @@ -159,7 +159,7 @@ def run_self_test(cls, output: bool = True, error_callback: Optional[Callable[[A cls.get_runtime_versions() usage = '[%.3fs, %d KB]' % (proc.execution_time, proc.max_memory) print_ansi( - "%s %-19s" % (['#ansi[Failed](red|bold) ', '#ansi[Success](green|bold)'][res], usage), end=' ' + '%s %-19s' % (['#ansi[Failed](red|bold) ', '#ansi[Success](green|bold)'][res], usage), end=' ' ) runtime_version: List[Tuple[str, str]] = [] @@ -167,7 +167,7 @@ def run_self_test(cls, output: bool = True, error_callback: Optional[Callable[[A assert version is not None runtime_version.append((runtime, '.'.join(map(str, version)))) - print_ansi(', '.join(["#ansi[%s](cyan|bold) %s" % v for v in runtime_version])) + print_ansi(', '.join(['#ansi[%s](cyan|bold) %s' % v for v in runtime_version])) if stdout.strip() != test_message and error_callback: error_callback('Got unexpected stdout output:\n' + utf8text(stdout)) if stderr: diff --git a/dmoj/executors/java_executor.py b/dmoj/executors/java_executor.py index 5d0b829ac..58a09c809 100644 --- a/dmoj/executors/java_executor.py +++ b/dmoj/executors/java_executor.py @@ -129,11 +129,11 @@ def parse_feedback_from_stderr(self, stderr, process): pass if b'Error: Main method not found in class' in stderr: - exception = "public static void main(String[] args) not found" + exception = 'public static void main(String[] args) not found' else: match = deque(reexception.finditer(utf8text(stderr, 'replace')), maxlen=1) if not match: - exception = "abnormal termination" # Probably exited without calling shutdown hooks + exception = 'abnormal termination' # Probably exited without calling shutdown hooks else: exception = match[0].group(1).split(':')[0] diff --git a/dmoj/executors/python_executor.py b/dmoj/executors/python_executor.py index 2addd9061..8a5b43eeb 100644 --- a/dmoj/executors/python_executor.py +++ b/dmoj/executors/python_executor.py @@ -9,19 +9,19 @@ class PythonExecutor(CompiledExecutor): - loader_script = '''\ + loader_script = """\ import runpy, sys, os del sys.argv[0] sys.stdin = os.fdopen(0, 'r', 65536) sys.stdout = os.fdopen(1, 'w', 65536) runpy.run_path(sys.argv[0], run_name='__main__') -''' +""" - unbuffered_loader_script = '''\ + unbuffered_loader_script = """\ import runpy, sys del sys.argv[0] runpy.run_path(sys.argv[0], run_name='__main__') -''' +""" address_grace = 131072 ext = 'py' diff --git a/dmoj/judge.py b/dmoj/judge.py index 2cf12c0c8..640ea1c1e 100644 --- a/dmoj/judge.py +++ b/dmoj/judge.py @@ -162,7 +162,7 @@ def _grading_thread_main(self, ipc_ready_signal: threading.Event, report) -> Non handler_func = ipc_handler_dispatch[ipc_type] except KeyError: raise RuntimeError( - "judge got unexpected IPC message from worker: %s" % ((ipc_type, data),) + 'judge got unexpected IPC message from worker: %s' % ((ipc_type, data),) ) from None handler_func(report, *data) @@ -222,7 +222,7 @@ def _ipc_result(self, report, batch_number: Optional[int], case_number: int, res def _ipc_batch_begin(self, report, batch_number: int) -> None: self.packet_manager.batch_begin_packet() - report(ansi_style("#ansi[Batch #%d](yellow|bold)" % batch_number)) + report(ansi_style('#ansi[Batch #%d](yellow|bold)' % batch_number)) def _ipc_batch_end(self, _report, _batch_number: int) -> None: self.packet_manager.batch_end_packet() @@ -232,7 +232,7 @@ def _ipc_grading_aborted(self, report) -> None: report(ansi_style('#ansi[Forcefully terminating grading. Temporary files may not be deleted.](red|bold)')) def _ipc_unhandled_exception(self, _report, message: str) -> None: - logger.error("Unhandled exception in worker process") + logger.error('Unhandled exception in worker process') self.log_internal_error(message=message) def abort_grading(self, submission_id: Optional[int] = None) -> None: @@ -305,7 +305,7 @@ def __init__(self, submission: Submission) -> None: self.worker_process_conn, child_conn = multiprocessing.Pipe() self.worker_process = multiprocessing.Process( - name="DMOJ Judge Handler for %s/%d" % (self.submission.problem_id, self.submission.id), + name='DMOJ Judge Handler for %s/%d' % (self.submission.problem_id, self.submission.id), target=self._worker_process_main, args=(child_conn, self.worker_process_conn), ) @@ -325,7 +325,7 @@ def communicate(self) -> Generator[Tuple[IPC, tuple], None, None]: self.worker_process.kill() raise except Exception: - logger.error("Failed to read IPC message from worker!") + logger.error('Failed to read IPC message from worker!') raise if ipc_type == IPC.BYE: @@ -343,7 +343,7 @@ def wait_with_timeout(self, timeout=IPC_TEARDOWN_TIMEOUT) -> None: logger.exception('Exception while waiting for worker to shut down, ignoring...') finally: if self.worker_process.is_alive(): - logger.error("Worker is still alive, sending SIGKILL!") + logger.error('Worker is still alive, sending SIGKILL!') self.worker_process.kill() def request_abort_grading(self) -> None: @@ -352,7 +352,7 @@ def request_abort_grading(self) -> None: try: self.worker_process_conn.send((IPC.REQUEST_ABORT, ())) except Exception: - logger.exception("Failed to send abort request to worker, did it race?") + logger.exception('Failed to send abort request to worker, did it race?') def _worker_process_main( self, @@ -374,7 +374,7 @@ def _ipc_recv_thread_main() -> None: try: ipc_type, data = judge_process_conn.recv() except: # noqa: E722, whatever happened, we have to abort now. - logger.exception("Judge unexpectedly hung up!") + logger.exception('Judge unexpectedly hung up!') self._do_abort() return @@ -383,7 +383,7 @@ def _ipc_recv_thread_main() -> None: elif ipc_type == IPC.REQUEST_ABORT: self._do_abort() else: - raise RuntimeError("worker got unexpected IPC message from judge: %s" % ((ipc_type, data),)) + raise RuntimeError('worker got unexpected IPC message from judge: %s' % ((ipc_type, data),)) def _report_unhandled_exception() -> None: # We can't pickle the whole traceback object, so just send the formatted exception. @@ -426,7 +426,7 @@ def _report_unhandled_exception() -> None: # this case, since we're blocking the main judge from proceeding. ipc_recv_thread.join(timeout=IPC_TEARDOWN_TIMEOUT) if ipc_recv_thread.is_alive(): - logger.error("Judge IPC recv thread is still alive after timeout, shutting worker down anyway!") + logger.error('Judge IPC recv thread is still alive after timeout, shutting worker down anyway!') # FIXME(tbrindus): we need to do this because cleaning up temporary directories happens on __del__, which # won't get called if we exit the process right now (so we'd leak all files created by the grader). This diff --git a/dmoj/problem.py b/dmoj/problem.py index f6a7d1ec8..794099656 100644 --- a/dmoj/problem.py +++ b/dmoj/problem.py @@ -224,7 +224,7 @@ def __init__(self, batch_no, config, problem, cases): self.points = config.points self.batched_cases = cases if any(isinstance(case, BatchedTestCase) for case in self.batched_cases): - raise InvalidInitException("nested batches") + raise InvalidInitException('nested batches') self.problem = problem def __str__(self): @@ -243,7 +243,7 @@ def __init__(self, count, batch_no, config, problem): self._generated = None def _normalize(self, data): - # Perhaps the correct answer may be "no output", in which case it'll be + # Perhaps the correct answer may be 'no output', in which case it'll be # None here if sourced from a generator. data = data or b'' @@ -285,7 +285,7 @@ def _run_generator(self, gen, args=None): elif isinstance(gen.source.unwrap(), list): filenames = list(gen.source.unwrap()) else: - raise InvalidInitException("invalid generator declaration") + raise InvalidInitException('invalid generator declaration') if gen.flags: flags += gen.flags diff --git a/dmoj/tests/test_malformed_unicode.py b/dmoj/tests/test_malformed_unicode.py index 16853ff00..d394deb3f 100644 --- a/dmoj/tests/test_malformed_unicode.py +++ b/dmoj/tests/test_malformed_unicode.py @@ -6,11 +6,11 @@ class ProblemTest(unittest.TestCase): def test_malformed_unicode(self): - source = b'''\ + source = b"""\ public class malformed { public static void main(String[] args){ S = "\xc1\xbf"; // This is malformed unicode } -}''' +}""" with self.assertRaisesRegex(CompileError, 'Your UTF-8 is bad, and you should feel bad'): JAVA8Executor('malformed', source) diff --git a/dmoj/utils/os_ext.py b/dmoj/utils/os_ext.py index 54f75d112..6cc7bb6a0 100644 --- a/dmoj/utils/os_ext.py +++ b/dmoj/utils/os_ext.py @@ -22,8 +22,8 @@ def oom_score_adj(score, to=None): def strsignal(signo): # in large part from http://code.activestate.com/recipes/578899-strsignal/ - libc = ctypes.CDLL(ctypes.util.find_library("c")) - strsignal_c = ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_int)(("strsignal", libc), ((1,),)) + libc = ctypes.CDLL(ctypes.util.find_library('c')) + strsignal_c = ctypes.CFUNCTYPE(ctypes.c_char_p, ctypes.c_int)(('strsignal', libc), ((1,),)) NSIG = signal.NSIG # The behavior of the C library strsignal() is unspecified if @@ -32,8 +32,8 @@ def strsignal(signo): if 0 <= signo < NSIG: s = strsignal_c(signo) if s: - return s.decode("utf-8") - return "Unknown signal %d" % signo + return s.decode('utf-8') + return 'Unknown signal %d' % signo def bool_env(name):