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_wrapped_paginator():
paginator = WrappedPaginator(max_size=200)
paginator.add_line("abcde " * 50)
assert len(paginator.pages) == 2
paginator = WrappedPaginator(max_size=200, include_wrapped=False)
paginator.add_line("abcde " * 50)
assert len(paginator.pages) == 2
def test_wrapped_paginator():
paginator = WrappedPaginator(max_size=200)
paginator.add_line("abcde " * 50)
assert len(paginator.pages) == 2
paginator = WrappedPaginator(max_size=200, include_wrapped=False)
paginator.add_line("abcde " * 50)
assert len(paginator.pages) == 2
scope = self.scope
try:
async with ReplResponseReactor(ctx.message):
with self.submit(ctx):
executor = AsyncCodeExecutor(argument.content, scope, arg_dict=arg_dict)
async for send, result in AsyncSender(executor):
self.last_result = result
header = repr(result).replace("``", "`\u200b`").replace(self.bot.http.token, "[token omitted]")
if len(header) > 485:
header = header[0:482] + "..."
paginator = WrappedPaginator(prefix=f"```prolog\n=== {header} ===\n", max_size=1985)
for name, res in all_inspections(result):
paginator.add_line(f"{name:16.16} :: {res}")
interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
send(await interface.send_to(ctx))
finally:
scope.clear_intersection(arg_dict)
if isinstance(result, discord.File):
send(await ctx.send(file=result))
elif isinstance(result, discord.Embed):
send(await ctx.send(embed=result))
elif isinstance(result, PaginatorInterface):
send(await result.send_to(ctx))
else:
if not isinstance(result, str):
# repr all non-strings
result = repr(result)
if len(result) > 2000:
# inconsistency here, results get wrapped in codeblocks when they are too large
# but don't if they're not. probably not that bad, but noting for later review
paginator = WrappedPaginator(prefix='```py', suffix='```', max_size=1985)
paginator.add_line(result)
interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
send(await interface.send_to(ctx))
else:
if result.strip() == '':
result = "\u200b"
send(await ctx.send(result.replace(self.bot.http.token, "[token omitted]")))
finally:
scope.clear_intersection(arg_dict)
async def jsk_unload(self, ctx: commands.Context, *extensions: ExtensionConverter):
"""
Unloads the given extension names.
Reports any extensions that failed to unload.
"""
paginator = WrappedPaginator(prefix='', suffix='')
icon = "\N{OUTBOX TRAY}"
for extension in itertools.chain(*extensions):
try:
self.bot.unload_extension(extension)
except Exception as exc: # pylint: disable=broad-except
traceback_data = "".join(traceback.format_exception(type(exc), exc, exc.__traceback__, 1))
paginator.add_line(
f"{icon}\N{WARNING SIGN} `{extension}`\n```py\n{traceback_data}\n```",
empty=True
)
else:
paginator.add_line(f"{icon} `{extension}`", empty=True)
for page in paginator.pages:
"""
Executes git statements in the system shell.
This uses the system shell as defined in $SHELL, or `/bin/bash` otherwise.
Execution can be cancelled by closing the paginator.
"""
message = message if message is not None else "Updated files."
if pull_push == "push":
shellcmd = f'sudo git add .&&sudo git commit -m "{message}"&&sudo git push'
elif pull_push == "pull":
shellcmd = 'sudo git pull'
else:
return await ctx.send("Invalid option given")
async with ReplResponseReactor(ctx.message):
paginator = WrappedPaginator(prefix="```sh", max_size=1985)
paginator.add_line(f"$ git {pull_push}\n")
interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
self.bot.loop.create_task(interface.send_to(ctx))
with ShellReader(shellcmd) as reader:
async for line in reader:
if interface.closed:
return
await interface.add_line(line)