Restyled by black

This commit is contained in:
Restyled.io
2021-05-22 01:26:33 +00:00
parent 58e8ba2347
commit 544c57ff1f
52 changed files with 3303 additions and 2729 deletions

View File

@@ -19,7 +19,8 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
_channels: typing.Dict[int, Channel] = {}
_seqHolder: int = 0
_seqHolderLock: threading.Condition = threading.Condition()
_executorService: concurrent.futures.ThreadPoolExecutor = concurrent.futures.ThreadPoolExecutor(
_executorService: concurrent.futures.ThreadPoolExecutor = (
concurrent.futures.ThreadPoolExecutor()
)
_session: Session = None
@@ -37,8 +38,8 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
out.write_short(channel.chunkId)
out.write_int(0x00000000)
out.write_int(0x00000000)
out.write_int(0x00004e20)
out.write_int(0x00030d40)
out.write_int(0x00004E20)
out.write_int(0x00030D40)
out.write(file_id)
out.write_int(start)
out.write_int(end)
@@ -53,7 +54,9 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
if channel is None:
self._LOGGER.warning(
"Couldn't find channel, id: {}, received: {}".format(
chunk_id, len(packet.payload)))
chunk_id, len(packet.payload)
)
)
return
channel._add_to_queue(payload)
@@ -63,14 +66,18 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
if channel is None:
self._LOGGER.warning(
"Dropping channel error, id: {}, code: {}".format(
chunk_id, payload.read_short()))
chunk_id, payload.read_short()
)
)
return
channel.stream_error(payload.read_short())
else:
self._LOGGER.warning(
"Couldn't handle packet, cmd: {}, payload: {}".format(
packet.cmd, Utils.Utils.bytes_to_hex(packet.payload)))
packet.cmd, Utils.Utils.bytes_to_hex(packet.payload)
)
)
def close(self) -> None:
self._executorService.shutdown()
@@ -84,8 +91,9 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
_buffer: BytesOutputStream = BytesOutputStream()
_header: bool = True
def __init__(self, channel_manager: ChannelManager, file: AudioFile,
chunk_index: int):
def __init__(
self, channel_manager: ChannelManager, file: AudioFile, chunk_index: int
):
self._channelManager = channel_manager
self._file = file
self._chunkIndex = chunk_index
@@ -94,17 +102,18 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
self._channelManager._seqHolder += 1
self._channelManager._executorService.submit(
lambda: ChannelManager.Channel.Handler(self))
lambda: ChannelManager.Channel.Handler(self)
)
def _handle(self, payload: BytesInputStream) -> bool:
if len(payload.buffer) == 0:
if not self._header:
self._file.write_chunk(bytearray(payload.buffer),
self._chunkIndex, False)
self._file.write_chunk(
bytearray(payload.buffer), self._chunkIndex, False
)
return True
self._channelManager._LOGGER.debug(
"Received empty chunk, skipping.")
self._channelManager._LOGGER.debug("Received empty chunk, skipping.")
return False
if self._header:
@@ -115,8 +124,9 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
break
header_id = payload.read_byte()
header_data = payload.read(length - 1)
self._file.write_header(int.from_bytes(header_id, "big"),
bytearray(header_data), False)
self._file.write_header(
int.from_bytes(header_id, "big"), bytearray(header_data), False
)
self._header = False
else:
self._buffer.write(payload.read(len(payload.buffer)))
@@ -137,11 +147,12 @@ class ChannelManager(Closeable, PacketsReceiver.PacketsReceiver):
def run(self) -> None:
self._channel._channelManager._LOGGER.debug(
"ChannelManager.Handler is starting")
"ChannelManager.Handler is starting"
)
with self._channel._q.all_tasks_done:
self._channel._channelManager._channels.pop(
self._channel.chunkId)
self._channel._channelManager._channels.pop(self._channel.chunkId)
self._channel._channelManager._LOGGER.debug(
"ChannelManager.Handler is shutting down")
"ChannelManager.Handler is shutting down"
)