Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_tb(writer, backtrace):
logger.add(writer, backtrace=backtrace, colorize=False, format="{message}")
try:
1 / 0
except ZeroDivisionError:
ex_type, ex, tb = sys.exc_info()
tb = None
logger.opt(exception=(ex_type, ex, tb)).debug("Test")
result = writer.read()
assert result == "Test\nZeroDivisionError: division by zero\n"
def test_ansi_nested(writer, colorize):
logger.add(writer, format="([{message}])", colorize=colorize)
logger.opt(ansi=True).debug("ABCDE")
assert writer.read() == parse(
"([ABCDE])\n", colorize=colorize
)
def test_ansi_multiple_calls(writer, colorize):
logger.add(writer, format="{message}", colorize=colorize)
logger.opt(ansi=True).debug("a foo b")
logger.opt(ansi=True).debug("a foo b")
assert writer.read() == parse("a foo b\na foo b\n", colorize=colorize)
return "trim", _args
else:
return _args[0], _args[1:]
if len(args) == 0:
command_name, args = parse_command(config_args)
else:
command_name, args = parse_command(args)
if config_args:
args = config_args + args
try:
command = commands[command_name]
retcode, summary = command.execute(args)
if "exception" in summary:
logger.opt(exception=summary["exception"]["details"]).error(
f"Error executing command {command_name}"
)
return retcode
except:
logger.exception(f"Error executing command: {command_name}")
return ReturnCode.ERROR
message=message.message_id,
chat=chat.id,
age=datetime.datetime.now() - message.date,
)
return False
if message.from_user not in message.new_chat_members:
logger.opt(lazy=True).info(
"User {user} add new members to chat {chat}: {new_members}",
user=lambda: message.from_user.id,
chat=lambda: message.chat.id,
new_members=lambda: ", ".join([str(u.id) for u in message.new_chat_members]),
)
# TODO: Validate is admin add new members
else:
logger.opt(lazy=True).info(
"New chat members in chat {chat}: {new_members}",
chat=lambda: message.chat.id,
new_members=lambda: ", ".join([str(u.id) for u in message.new_chat_members]),
)
users = {}
for new_member in message.new_chat_members:
try:
await message.chat.restrict(
new_member.id, permissions=types.ChatPermissions(can_send_messages=False)
)
users[new_member.id] = new_member.get_mention()
except BadRequest as e:
logger.error(
"Cannot restrict chat member {user} in chat {chat} with error: {error}",
user=new_member.id,
async def trash(paths: Sequence[Path], parent: PurePath, *, missing_ok: bool = False) -> None:
dst = await amkdtemp(dir=parent, prefix='deleted-' + paths[0].name + '-')
for path in map(str, paths): # https://bugs.python.org/issue32689
try:
await amove(path, dst)
except (FileNotFoundError if missing_ok else ()):
logger.opt(exception=True).info('source missing')
if args.show_start:
startcanvas = matrix.CreateFrameCanvas(writeppm)
startscreen(startcanvas, fontsmall, lighttextColor, ifopt, ppm_smile)
matrix.SwapOnVSync(startcanvas)
sleep(5)
while True:
try:
with ProcessPoolExecutor(max_workers=1) as ppe:
loop(matrix, ppe, args.sleep_interval)
except KeyboardInterrupt:
break
except NoDatasourceException as nde:
logger.exception(nde)
break
except Exception:
logger.opt(exception=True).critical("exception in loop or module")
logger.info("exiting")
n_classes=len(est.classes_),
is_binary=len(est.classes_) == 2
)
L.info('Meta info (keys): {}'.format(self.meta_info.keys()))
L.opt(lazy=True).debug('Meta info: {}'.format(self.meta_info))
if self.meta_info['is_binary']:
self.model_data = dict(
coeffs=est.coef_[0].tolist(), inters=est.intercept_[0].tolist()
)
else:
self.model_data = dict(
coeffs=est.coef_.tolist(), inters=est.intercept_.tolist()
)
L.info('Model data (keys): {}'.format(self.model_data.keys()))
L.opt(lazy=True).debug('Model data: {}'.format(self.model_data))
self.estimators = [
est.estimators_[idx] for idx in range(est.n_estimators)
]
self.n_estimators = len(self.estimators)
self.n_features = est.estimators_[0].n_features_
self.n_classes = est.n_classes_
# Extract and save meta information:
self.meta_info = dict(
n_estimators=est.n_estimators,
n_classes=est.n_classes_,
n_features=est.estimators_[0].n_features_,
)
L.info('Meta info (keys): {}'.format(self.meta_info.keys()))
L.opt(lazy=True).debug('Meta info: {}'.format(self.meta_info))
# Extract and save model data:
self.model_data['estimators'] = []
for e in est.estimators_:
self.model_data['estimators'].append(
dict(
lefts=e.tree_.children_left.tolist(),
rights=e.tree_.children_right.tolist(),
thresholds=e.tree_.threshold.tolist(),
classes=[c[0] for c in e.tree_.value.astype(int).tolist()],
indices=e.tree_.feature.tolist()
)
)
L.info('Model data (keys): {}'.format(self.model_data.keys()))
L.opt(lazy=True).debug('Model data: {}'.format(self.model_data))
logger.success(f"Removed download {download.gid}")
result.append(True)
try:
self.client.remove_download_result(download.gid)
except ClientException as error2:
logger.debug(f"Failed to remove download result {download.gid}")
logger.opt(exception=True).trace(error2)
if removed_gid != download.gid:
logger.debug(
f"Removed download GID#{removed_gid} is different than download GID#{download.gid}"
)
try:
self.client.remove_download_result(removed_gid)
except ClientException as error2:
logger.debug(f"Failed to remove download result {removed_gid}")
logger.opt(exception=True).trace(error2)
if clean:
# FUTURE: use missing_ok parameter on Python 3.8
try:
download.control_file_path.unlink()
except FileNotFoundError:
logger.debug(f"aria2 control file {download.control_file_path} was not found")
else:
logger.debug(f"Removed control file {download.control_file_path}")
if files and result[-1]:
self.remove_files([download], force=True)
return result