__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
"""
Buffer byte streams.
"""
from itertools import count
from typing import Dict, Iterator, List, TypeVar
from attrs import Factory, define
from twisted.protocols.amp import AMP, Command, Integer, String as Bytes
T = TypeVar("T")
class StreamOpen(Command):
"""
Open a new stream.
"""
response = [(b"streamId", Integer())]
class StreamWrite(Command):
"""
Write a chunk of data to a stream.
"""
arguments = [
(b"streamId", Integer()),
(b"data", Bytes()),
]
@define
class StreamReceiver:
"""
Buffering de-multiplexing byte stream receiver.
"""
_counter: Iterator[int] = count()
_streams: Dict[int, List[bytes]] = Factory(dict)
def open(self) -> int:
"""
Open a new stream and return its unique identifier.
"""
newId = next(self._counter)
self._streams[newId] = []
return newId
def write(self, streamId: int, chunk: bytes) -> None:
"""
Write to an open stream using its unique identifier.
@raise KeyError: If there is no such open stream.
"""
self._streams[streamId].append(chunk)
def finish(self, streamId: int) -> List[bytes]:
"""
Indicate an open stream may receive no further data and return all of
its current contents.
@raise KeyError: If there is no such open stream.
"""
return self._streams.pop(streamId)
def chunk(data: bytes, chunkSize: int) -> Iterator[bytes]:
"""
Break a byte string into pieces of no more than ``chunkSize`` length.
@param data: The byte string.
@param chunkSize: The maximum length of the resulting pieces. All pieces
except possibly the last will be this length.
@return: The pieces.
"""
pos = 0
while pos < len(data):
yield data[pos : pos + chunkSize]
pos += chunkSize
async def stream(amp: AMP, chunks: Iterator[bytes]) -> int:
"""
Send the given stream chunks, one by one, over the given connection.
The chunks are sent using L{StreamWrite} over a stream opened using
L{StreamOpen}.
@return: The identifier of the stream over which the chunks were sent.
"""
streamId = (await amp.callRemote(StreamOpen))["streamId"]
assert isinstance(streamId, int)
for oneChunk in chunks:
await amp.callRemote(StreamWrite, streamId=streamId, data=oneChunk)
return streamId
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| test | Folder | 0755 |
|
|
| __init__.py | File | 1.9 KB | 0644 |
|
| distreporter.py | File | 2.58 KB | 0644 |
|
| disttrial.py | File | 16.22 KB | 0644 |
|
| functional.py | File | 2.88 KB | 0644 |
|
| managercommands.py | File | 1.73 KB | 0644 |
|
| options.py | File | 737 B | 0644 |
|
| stream.py | File | 2.38 KB | 0644 |
|
| worker.py | File | 14.1 KB | 0644 |
|
| workercommands.py | File | 574 B | 0644 |
|
| workerreporter.py | File | 11.32 KB | 0644 |
|
| workertrial.py | File | 2.37 KB | 0644 |
|