Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cmd += [
f"https://{self.host}:{self.port}/{request.method}",
"-H",
"Content-Type: application/json",
"--data-binary",
f"@{nf.name}",
"-w \\n%{http_code}",
]
if self.ca:
cmd.extend(["--cacert", self.ca])
if self.key:
cmd.extend(["--key", self.key])
if self.cert:
cmd.extend(["--cert", self.cert])
LOG.debug(f"Running: {' '.join(cmd)}")
rc = subprocess.run(cmd, capture_output=True)
if rc.returncode != 0:
if rc.returncode == 60:
raise CurlClientSSLException
LOG.error(rc.stderr)
raise RuntimeError(f"Curl failed with return code {rc.returncode}")
# The response status code is displayed on the last line of
# the output (via -w option)
rep, status_code = rc.stdout.decode().rsplit("\n", 1)
if int(status_code) != 200:
LOG.error(rep)
raise RuntimeError(f"Curl failed with status code {status_code}")
self.stream.update(rep.encode())
def test(*, backtrace, colorize, diagnose):
logger.remove()
logger.add(sys.stderr, format="", colorize=colorize, backtrace=backtrace, diagnose=diagnose)
try:
divide_indirect(10, 0)
except ZeroDivisionError:
logger.exception("")
def test_remove_in_main_process_inheritance():
writer = Writer()
barrier = multiprocessing.Barrier(2)
logger.add(writer, format="{message}", enqueue=True, catch=False)
process = multiprocessing.Process(target=subworker_barrier_inheritance, args=(barrier,))
process.start()
barrier.wait()
logger.info("Main")
logger.remove()
process.join()
assert process.exitcode == 0
assert writer.read() == "Child\nMain\n"
def test(diagnose, backtrace):
logger.remove()
logger.add(sys.stderr, format="", diagnose=diagnose, backtrace=backtrace, colorize=True)
try:
1 / 0
except ZeroDivisionError:
type_, value, _ = sys.exc_info()
logger.opt(exception=(type_, value, None)).error("")
def test(diagnose, backtrace):
logger.remove()
logger.add(sys.stderr, format="", diagnose=diagnose, backtrace=backtrace, colorize=True)
try:
assert False
except AssertionError:
type_, value, _ = sys.exc_info()
logger.opt(exception=(type_, value, None)).error("")
check = infra.checker.Checker()
rs = log_msgs(primary, txs)
check_responses(rs, True, check, check_commit)
network.wait_for_node_commit_sync()
check_nodes_have_msgs(backups, txs)
recovered_network = test(network, args)
network.stop_all_nodes()
network = recovered_network
old_txs = Txs(args.msgs_per_recovery, recovery_idx, since_beginning=True)
check_nodes_have_msgs(recovered_network.nodes, old_txs)
LOG.success("Recovery complete on all nodes")
def test_contextualize_after_configure(writer):
logger.add(writer, format="{message} {extra[foobar]}")
with logger.contextualize(foobar="baz"):
logger.configure(extra={"foobar": "baz_2"})
logger.info("A")
logger.info("B")
assert writer.read() == "A baz\nB baz_2\n"
def test_stream_handler(capsys):
logger.add(StreamHandler(sys.stderr), format="{level} {message}")
logger.info("test")
logger.remove()
logger.warning("nope")
out, err = capsys.readouterr()
assert out == ""
assert err == "INFO test\n"
def test_nested_contextualize(writer):
logger.add(writer, format="{message} {extra[foobar]}")
with logger.contextualize(foobar="a"):
with logger.contextualize(foobar="b"):
logger.info("B")
logger.info("A")
with logger.contextualize(foobar="c"):
logger.info("C")
assert writer.read() == "B b\nA a\nC c\n"
import sys
from loguru import logger
logger.remove()
logger.add(sys.stderr, format="", colorize=False, backtrace=False, diagnose=False)
logger.add(sys.stderr, format="", colorize=False, backtrace=True, diagnose=False)
@logger.catch(ZeroDivisionError)
def foo():
bar()
@logger.catch(NotImplementedError)
def bar():
1 / 0
foo()