mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
@@ -73,7 +73,9 @@ async def subprocess_check_output(*args, cwd=None, env=None, stderr=False):
|
||||
proc = await asyncio.create_subprocess_exec(*args, stderr=asyncio.subprocess.PIPE, cwd=cwd, env=env)
|
||||
_, output = await proc.communicate()
|
||||
else:
|
||||
proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL, cwd=cwd, env=env)
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL, cwd=cwd, env=env
|
||||
)
|
||||
output, _ = await proc.communicate()
|
||||
if output is None:
|
||||
return ""
|
||||
|
||||
@@ -56,20 +56,24 @@ def _get_compressor(compress_type, compresslevel=None):
|
||||
|
||||
if compress_type == zipfile.ZIP_DEFLATED:
|
||||
from zipfile import zlib
|
||||
|
||||
if compresslevel is not None:
|
||||
return zlib.compressobj(compresslevel, zlib.DEFLATED, -15)
|
||||
return zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15)
|
||||
elif compress_type == zipfile.ZIP_BZIP2:
|
||||
from zipfile import bz2
|
||||
|
||||
if compresslevel is not None:
|
||||
return bz2.BZ2Compressor(compresslevel)
|
||||
return bz2.BZ2Compressor()
|
||||
# compresslevel is ignored for ZIP_LZMA
|
||||
elif compress_type == zipfile.ZIP_LZMA:
|
||||
from zipfile import LZMACompressor
|
||||
|
||||
return LZMACompressor()
|
||||
elif compress_type == ZIP_ZSTANDARD:
|
||||
import zstandard as zstd
|
||||
|
||||
if compresslevel is not None:
|
||||
# for threads param a value of -1 means to set the number of threads to the number of detected logical CPUs
|
||||
return zstd.ZstdCompressor(level=compresslevel, threads=-1).compressobj()
|
||||
@@ -141,13 +145,13 @@ class ZipInfo(zipfile.ZipInfo):
|
||||
|
||||
class ZipFile(zipfile.ZipFile):
|
||||
def __init__(
|
||||
self,
|
||||
fileobj=None,
|
||||
mode="w",
|
||||
compression=zipfile.ZIP_STORED,
|
||||
allowZip64=True,
|
||||
compresslevel=None,
|
||||
chunksize=32768
|
||||
self,
|
||||
fileobj=None,
|
||||
mode="w",
|
||||
compression=zipfile.ZIP_STORED,
|
||||
allowZip64=True,
|
||||
compresslevel=None,
|
||||
chunksize=32768,
|
||||
):
|
||||
"""Open the ZIP file with mode write "w"."""
|
||||
|
||||
@@ -158,11 +162,7 @@ class ZipFile(zipfile.ZipFile):
|
||||
|
||||
self._comment = b""
|
||||
zipfile.ZipFile.__init__(
|
||||
self, fileobj,
|
||||
mode=mode,
|
||||
compression=compression,
|
||||
compresslevel=compresslevel,
|
||||
allowZip64=allowZip64
|
||||
self, fileobj, mode=mode, compression=compression, compresslevel=compresslevel, allowZip64=allowZip64
|
||||
)
|
||||
self._chunksize = chunksize
|
||||
self.paths_to_write = []
|
||||
@@ -232,7 +232,7 @@ class ZipFile(zipfile.ZipFile):
|
||||
"filename": filename,
|
||||
"arcname": arcname,
|
||||
"compress_type": compress_type,
|
||||
"compresslevel": compresslevel
|
||||
"compresslevel": compresslevel,
|
||||
}
|
||||
self.paths_to_write.append(kwargs)
|
||||
|
||||
@@ -245,7 +245,7 @@ class ZipFile(zipfile.ZipFile):
|
||||
"arcname": arcname,
|
||||
"iterable": iterable,
|
||||
"compress_type": compress_type,
|
||||
"compresslevel": compresslevel
|
||||
"compresslevel": compresslevel,
|
||||
}
|
||||
self.paths_to_write.append(kwargs)
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class EmbedShell:
|
||||
if not cmd[0].strip():
|
||||
return ""
|
||||
|
||||
for (name, meth) in inspect.getmembers(self):
|
||||
for name, meth in inspect.getmembers(self):
|
||||
if name == cmd[0]:
|
||||
cmd.pop(0)
|
||||
res = await meth(*cmd)
|
||||
@@ -177,10 +177,10 @@ class UnstoppableEventLoop(EventLoop):
|
||||
self._loop = loop
|
||||
|
||||
def close(self):
|
||||
" Ignore. "
|
||||
"Ignore."
|
||||
|
||||
def stop(self):
|
||||
" Ignore. "
|
||||
"Ignore."
|
||||
|
||||
def run_in_executor(self, *args, **kwargs):
|
||||
return self._loop.run_in_executor(*args, **kwargs)
|
||||
@@ -264,18 +264,18 @@ class ShellConnection(TelnetConnection):
|
||||
self.reset()
|
||||
|
||||
def reset(self):
|
||||
""" Resets terminal screen"""
|
||||
"""Resets terminal screen"""
|
||||
self._cli.reset()
|
||||
self._cli.buffers[DEFAULT_BUFFER].reset()
|
||||
self._cli.renderer.request_absolute_cursor_position()
|
||||
self._cli._redraw()
|
||||
|
||||
def write(self, data):
|
||||
""" Compat with CLI"""
|
||||
"""Compat with CLI"""
|
||||
self.send(data)
|
||||
|
||||
def flush(self):
|
||||
""" Compat with CLI"""
|
||||
"""Compat with CLI"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ Parser for VT100 input stream.
|
||||
|
||||
# Copied from prompt_toolkit/terminal/vt100_input.py due to dependency on termios (which is not available on Windows)
|
||||
|
||||
|
||||
import re
|
||||
import six
|
||||
|
||||
@@ -40,7 +39,7 @@ _mouse_event_prefix_re = re.compile("^" + re.escape("\x1b[") + r"(<?[\d;]*|M.{0,
|
||||
|
||||
|
||||
class _Flush:
|
||||
""" Helper object to indicate flush operation to the parser. """
|
||||
"""Helper object to indicate flush operation to the parser."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class AsyncioRawCommandServer:
|
||||
*self._command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.STDOUT,
|
||||
stdin=asyncio.subprocess.PIPE
|
||||
stdin=asyncio.subprocess.PIPE,
|
||||
)
|
||||
try:
|
||||
await self._process(network_reader, network_writer, process.stdout, process.stdin)
|
||||
|
||||
@@ -119,9 +119,9 @@ class AsyncioTelnetServer:
|
||||
:param keepalive_interval: interval in seconds for sending NOP keep-alive (0 to disable).
|
||||
"""
|
||||
|
||||
assert connection_factory is None or (
|
||||
connection_factory is not None and reader is None and writer is None
|
||||
), "Please use either reader and writer either connection_factory, otherwise duplicate data may be produced."
|
||||
assert connection_factory is None or (connection_factory is not None and reader is None and writer is None), (
|
||||
"Please use either reader and writer either connection_factory, otherwise duplicate data may be produced."
|
||||
)
|
||||
|
||||
self._reader = reader
|
||||
self._writer = writer
|
||||
|
||||
Reference in new issue
Block a user