Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
proc = subprocess.Popen([sys.executable, "random_attack.py", str(seed)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=utf8_env)
try:
out, err = proc.communicate(timeout=100)
except subprocess.TimeoutExpired:
proc.kill()
out, err = proc.communicate()
rc = proc.returncode
if rc == 0 and skip_successful_seeds:
return True
if rc == 0:
status = term.color("bright_green", "OK")
elif rc > 0:
status = term.color("yellow", "FAIL")
elif rc == -9:
status = term.color("cyan", "HANG")
else:
status = term.color("bright_red", "ABORT")
if rc != 0:
status += " (%d)" % rc
print("%-19d: %s" % (seed, status))
if save_logs_to_file:
write_to_file("random_attack_logs/%d.txt" % seed, out, err)
else:
write_to_screen(out, err)
return rc == 0
utf8_env = os.environ
utf8_env['PYTHONIOENCODING'] = 'utf-8'
proc = subprocess.Popen([sys.executable, "random_attack.py", str(seed)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=utf8_env)
try:
out, err = proc.communicate(timeout=100)
except subprocess.TimeoutExpired:
proc.kill()
out, err = proc.communicate()
rc = proc.returncode
if rc == 0 and skip_successful_seeds:
return True
if rc == 0:
status = term.color("bright_green", "OK")
elif rc > 0:
status = term.color("yellow", "FAIL")
elif rc == -9:
status = term.color("cyan", "HANG")
else:
status = term.color("bright_red", "ABORT")
if rc != 0:
status += " (%d)" % rc
print("%-19d: %s" % (seed, status))
if save_logs_to_file:
write_to_file("random_attack_logs/%d.txt" % seed, out, err)
else:
write_to_screen(out, err)
return rc == 0
env=utf8_env)
try:
out, err = proc.communicate(timeout=100)
except subprocess.TimeoutExpired:
proc.kill()
out, err = proc.communicate()
rc = proc.returncode
if rc == 0 and skip_successful_seeds:
return True
if rc == 0:
status = term.color("bright_green", "OK")
elif rc > 0:
status = term.color("yellow", "FAIL")
elif rc == -9:
status = term.color("cyan", "HANG")
else:
status = term.color("bright_red", "ABORT")
if rc != 0:
status += " (%d)" % rc
print("%-19d: %s" % (seed, status))
if save_logs_to_file:
write_to_file("random_attack_logs/%d.txt" % seed, out, err)
else:
write_to_screen(out, err)
return rc == 0
try:
for i in range(n_attacks):
seed = random.getrandbits(63)
ret = try_seed(seed)
n_tests += 1
n_errors += not ret
if n_errors >= maxfail:
raise KeyboardInterrupt
if skip_successful_seeds:
print(term.color("bold", " Seeds tried: %d" % (i + 1)),
end="\r")
except KeyboardInterrupt:
errmsg = "errors: %d" % n_errors
if n_errors:
errmsg = term.color("bright_red", errmsg)
print("\r" + term.color("bright_cyan", "DONE.") +
" Seeds tested: %d, %s" % (n_tests, errmsg))
else:
opt = self._get_option(name)
if isinstance(opt, Config):
return opt.describe()
names = [name]
extras = ""
for name in names:
opt = self._get_option(name)
if isinstance(opt, Config):
extras += "%s [...]\n\n" % term.color("bold", opt.name)
continue
value = opt.get()
comment = ("(default)" if value == opt.default else
"(default: %r)" % opt.default)
print("%s = %s %s" %
(term.color("bold", opt.name),
term.color("bright_green", repr(value)),
term.color("bright_black", comment)))
for line in opt.doc.strip().split("\n"):
print(" " + line)
print()
if extras:
print(extras, end="")
def debug(self, message):
if message[0] != "[":
message = " " + message
print(term.color("bright_black", message), flush=True)
def _handle_(self, *exc_args):
if exc_args:
# Warning was converted into an exception
TTypeError._handle_(self, *exc_args)
else:
print(term.color("yellow", self.__class__.__name__ + ": ") +
term.color("bright_black", str(self)))
def header(self):
if self._width == 0:
return ""
else:
return term.color("bold", self._format(self._name)) + self._rmargin
def _handle_(self, *exc_args):
if exc_args:
# Warning was converted into an exception
TTypeError._handle_(self, *exc_args)
else:
print(term.color("yellow", self.__class__.__name__ + ": ") +
term.color("bright_black", str(self)))
grey = lambda s: term.color("bright_black", s)
header = ["".join(col.header for col in columns),