Skip to content

Commit

Permalink
deploy: b908255
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic committed Nov 24, 2023
1 parent 8ad3c12 commit 6a4870d
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 93 deletions.
94 changes: 57 additions & 37 deletions protocol/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ <h1 id="params">Params</h1>
&#34;&#34;&#34;
pass # pragma: no cover

@staticmethod
@abstractmethod
def decode_message(data: bytes) -&gt; dict:
&#34;&#34;&#34;
Decode a message from raw bytes.
&#34;&#34;&#34;
pass # pragma: no cover

def is_connected(self) -&gt; bool:
&#34;&#34;&#34;
Return whether or not the connection is still alive
Expand Down Expand Up @@ -477,6 +485,24 @@ <h3>Subclasses</h3>
</ul>
<h3>Static methods</h3>
<dl>
<dt id="server.protocol.Protocol.decode_message"><code class="name flex">
<span>def <span class="ident">decode_message</span></span>(<span>data: bytes) ‑> dict</span>
</code></dt>
<dd>
<div class="desc"><p>Decode a message from raw bytes.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@staticmethod
@abstractmethod
def decode_message(data: bytes) -&gt; dict:
&#34;&#34;&#34;
Decode a message from raw bytes.
&#34;&#34;&#34;
pass # pragma: no cover</code></pre>
</details>
</dd>
<dt id="server.protocol.Protocol.encode_message"><code class="name flex">
<span>def <span class="ident">encode_message</span></span>(<span>message: dict) ‑> bytes</span>
</code></dt>
Expand Down Expand Up @@ -843,6 +869,27 @@ <h1 id="errors">Errors</h1>

return QDataStreamProtocol.pack_message(json_encoder.encode(message))

@staticmethod
def decode_message(data: bytes) -&gt; dict:
_, action = QDataStreamProtocol.read_qstring(data)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in QDataStreamProtocol.read_block(data):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message

async def read_message(self):
&#34;&#34;&#34;
Read a message from the stream
Expand All @@ -859,24 +906,7 @@ <h1 id="errors">Errors</h1>
# Otherwise reraise
raise

pos, action = self.read_qstring(block)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in self.read_block(block):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message</code></pre>
return QDataStreamProtocol.decode_message(block)</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand Down Expand Up @@ -1045,24 +1075,7 @@ <h1 id="errors">Errors</h1>
# Otherwise reraise
raise

pos, action = self.read_qstring(block)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in self.read_block(block):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message</code></pre>
return QDataStreamProtocol.decode_message(block)</code></pre>
</details>
</dd>
</dl>
Expand All @@ -1071,6 +1084,7 @@ <h3>Inherited members</h3>
<li><code><b><a title="server.protocol.protocol.Protocol" href="protocol.html#server.protocol.protocol.Protocol">Protocol</a></b></code>:
<ul class="hlist">
<li><code><a title="server.protocol.protocol.Protocol.close" href="protocol.html#server.protocol.protocol.Protocol.close">close</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.decode_message" href="protocol.html#server.protocol.protocol.Protocol.decode_message">decode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.drain" href="protocol.html#server.protocol.protocol.Protocol.drain">drain</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.is_connected" href="protocol.html#server.protocol.protocol.Protocol.is_connected">is_connected</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.send_message" href="protocol.html#server.protocol.protocol.Protocol.send_message">send_message</a></code></li>
Expand Down Expand Up @@ -1098,11 +1112,15 @@ <h3>Inherited members</h3>
def encode_message(message: dict) -&gt; bytes:
return (json_encoder.encode(message) + &#34;\n&#34;).encode()

@staticmethod
def decode_message(data: bytes) -&gt; dict:
return json.loads(data.strip())

async def read_message(self) -&gt; dict:
line = await self.reader.readline()
if not line:
raise DisconnectedError()
return json.loads(line.strip())</code></pre>
return SimpleJsonProtocol.decode_message(line)</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand All @@ -1113,6 +1131,7 @@ <h3>Inherited members</h3>
<li><code><b><a title="server.protocol.protocol.Protocol" href="protocol.html#server.protocol.protocol.Protocol">Protocol</a></b></code>:
<ul class="hlist">
<li><code><a title="server.protocol.protocol.Protocol.close" href="protocol.html#server.protocol.protocol.Protocol.close">close</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.decode_message" href="protocol.html#server.protocol.protocol.Protocol.decode_message">decode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.drain" href="protocol.html#server.protocol.protocol.Protocol.drain">drain</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.encode_message" href="protocol.html#server.protocol.protocol.Protocol.encode_message">encode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.is_connected" href="protocol.html#server.protocol.protocol.Protocol.is_connected">is_connected</a></code></li>
Expand Down Expand Up @@ -1177,6 +1196,7 @@ <h4><code><a title="server.protocol.Protocol" href="#server.protocol.Protocol">P
<ul class="two-column">
<li><code><a title="server.protocol.Protocol.abort" href="#server.protocol.Protocol.abort">abort</a></code></li>
<li><code><a title="server.protocol.Protocol.close" href="#server.protocol.Protocol.close">close</a></code></li>
<li><code><a title="server.protocol.Protocol.decode_message" href="#server.protocol.Protocol.decode_message">decode_message</a></code></li>
<li><code><a title="server.protocol.Protocol.drain" href="#server.protocol.Protocol.drain">drain</a></code></li>
<li><code><a title="server.protocol.Protocol.encode_message" href="#server.protocol.Protocol.encode_message">encode_message</a></code></li>
<li><code><a title="server.protocol.Protocol.is_connected" href="#server.protocol.Protocol.is_connected">is_connected</a></code></li>
Expand Down
35 changes: 35 additions & 0 deletions protocol/protocol.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ <h1 class="title">Module <code>server.protocol.protocol</code></h1>
&#34;&#34;&#34;
pass # pragma: no cover

@staticmethod
@abstractmethod
def decode_message(data: bytes) -&gt; dict:
&#34;&#34;&#34;
Decode a message from raw bytes.
&#34;&#34;&#34;
pass # pragma: no cover

def is_connected(self) -&gt; bool:
&#34;&#34;&#34;
Return whether or not the connection is still alive
Expand Down Expand Up @@ -238,6 +246,14 @@ <h3>Ancestors</h3>
&#34;&#34;&#34;
pass # pragma: no cover

@staticmethod
@abstractmethod
def decode_message(data: bytes) -&gt; dict:
&#34;&#34;&#34;
Decode a message from raw bytes.
&#34;&#34;&#34;
pass # pragma: no cover

def is_connected(self) -&gt; bool:
&#34;&#34;&#34;
Return whether or not the connection is still alive
Expand Down Expand Up @@ -370,6 +386,24 @@ <h3>Subclasses</h3>
</ul>
<h3>Static methods</h3>
<dl>
<dt id="server.protocol.protocol.Protocol.decode_message"><code class="name flex">
<span>def <span class="ident">decode_message</span></span>(<span>data: bytes) ‑> dict</span>
</code></dt>
<dd>
<div class="desc"><p>Decode a message from raw bytes.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@staticmethod
@abstractmethod
def decode_message(data: bytes) -&gt; dict:
&#34;&#34;&#34;
Decode a message from raw bytes.
&#34;&#34;&#34;
pass # pragma: no cover</code></pre>
</details>
</dd>
<dt id="server.protocol.protocol.Protocol.encode_message"><code class="name flex">
<span>def <span class="ident">encode_message</span></span>(<span>message: dict) ‑> bytes</span>
</code></dt>
Expand Down Expand Up @@ -678,6 +712,7 @@ <h4><code><a title="server.protocol.protocol.Protocol" href="#server.protocol.pr
<ul class="two-column">
<li><code><a title="server.protocol.protocol.Protocol.abort" href="#server.protocol.protocol.Protocol.abort">abort</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.close" href="#server.protocol.protocol.Protocol.close">close</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.decode_message" href="#server.protocol.protocol.Protocol.decode_message">decode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.drain" href="#server.protocol.protocol.Protocol.drain">drain</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.encode_message" href="#server.protocol.protocol.Protocol.encode_message">encode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.is_connected" href="#server.protocol.protocol.Protocol.is_connected">is_connected</a></code></li>
Expand Down
100 changes: 46 additions & 54 deletions protocol/qdatastream.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,15 @@ <h1 class="title">Module <code>server.protocol.qdatastream</code></h1>

return QDataStreamProtocol.pack_message(json_encoder.encode(message))

async def read_message(self):
&#34;&#34;&#34;
Read a message from the stream

# Errors
Raises `IncompleteReadError` on malformed stream.
&#34;&#34;&#34;
try:
length, *_ = struct.unpack(&#34;!I&#34;, await self.reader.readexactly(4))
block = await self.reader.readexactly(length)
except IncompleteReadError as e:
if self.reader.at_eof() and not e.partial:
raise DisconnectedError()
# Otherwise reraise
raise

pos, action = self.read_qstring(block)
@staticmethod
def decode_message(data: bytes) -&gt; dict:
_, action = QDataStreamProtocol.read_qstring(data)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in self.read_block(block):
for part in QDataStreamProtocol.read_block(data):
try:
message_part = json.loads(part)
if part != action:
Expand All @@ -143,6 +129,24 @@ <h1 class="title">Module <code>server.protocol.qdatastream</code></h1>
pass
return message

async def read_message(self):
&#34;&#34;&#34;
Read a message from the stream

# Errors
Raises `IncompleteReadError` on malformed stream.
&#34;&#34;&#34;
try:
length, *_ = struct.unpack(&#34;!I&#34;, await self.reader.readexactly(4))
block = await self.reader.readexactly(length)
except IncompleteReadError as e:
if self.reader.at_eof() and not e.partial:
raise DisconnectedError()
# Otherwise reraise
raise

return QDataStreamProtocol.decode_message(block)


PING_MSG = QDataStreamProtocol.pack_message(&#34;PING&#34;)
PONG_MSG = QDataStreamProtocol.pack_message(&#34;PONG&#34;)</code></pre>
Expand Down Expand Up @@ -239,6 +243,27 @@ <h2 class="section-title" id="header-classes">Classes</h2>

return QDataStreamProtocol.pack_message(json_encoder.encode(message))

@staticmethod
def decode_message(data: bytes) -&gt; dict:
_, action = QDataStreamProtocol.read_qstring(data)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in QDataStreamProtocol.read_block(data):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message

async def read_message(self):
&#34;&#34;&#34;
Read a message from the stream
Expand All @@ -255,24 +280,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
# Otherwise reraise
raise

pos, action = self.read_qstring(block)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in self.read_block(block):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message</code></pre>
return QDataStreamProtocol.decode_message(block)</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
Expand Down Expand Up @@ -441,24 +449,7 @@ <h1 id="errors">Errors</h1>
# Otherwise reraise
raise

pos, action = self.read_qstring(block)
if action in (&#34;PING&#34;, &#34;PONG&#34;):
return {&#34;command&#34;: action.lower()}

message = json.loads(action)
try:
for part in self.read_block(block):
try:
message_part = json.loads(part)
if part != action:
message.update(message_part)
except (ValueError, TypeError):
if &#34;legacy&#34; not in message:
message[&#34;legacy&#34;] = []
message[&#34;legacy&#34;].append(part)
except (KeyError, ValueError):
pass
return message</code></pre>
return QDataStreamProtocol.decode_message(block)</code></pre>
</details>
</dd>
</dl>
Expand All @@ -467,6 +458,7 @@ <h3>Inherited members</h3>
<li><code><b><a title="server.protocol.protocol.Protocol" href="protocol.html#server.protocol.protocol.Protocol">Protocol</a></b></code>:
<ul class="hlist">
<li><code><a title="server.protocol.protocol.Protocol.close" href="protocol.html#server.protocol.protocol.Protocol.close">close</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.decode_message" href="protocol.html#server.protocol.protocol.Protocol.decode_message">decode_message</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.drain" href="protocol.html#server.protocol.protocol.Protocol.drain">drain</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.is_connected" href="protocol.html#server.protocol.protocol.Protocol.is_connected">is_connected</a></code></li>
<li><code><a title="server.protocol.protocol.Protocol.send_message" href="protocol.html#server.protocol.protocol.Protocol.send_message">send_message</a></code></li>
Expand Down
Loading

0 comments on commit 6a4870d

Please sign in to comment.