remove anything related to sending; we're just a state machine.

This commit is contained in:
jesopo 2020-03-15 21:25:17 +00:00
parent a379539af3
commit 5a0569a22f
3 changed files with 14 additions and 16 deletions

View File

@ -22,22 +22,23 @@ CHAN = "#chan"
HOST = "127.0.0.1"
POST = 6667
server = ircstates.Server("freenode")
sock = socket.socket()
server = ircstates.Server("freenode")
sock = socket.socket()
encoder = irctokens.StatefulEncoder()
sock.connect((HOST, POST))
def _send(raw):
tokens = irctokens.tokenise(raw)
server.send(tokens)
encoder.push(tokens)
_send("USER test 0 * test")
_send(f"NICK {NICK}")
while True:
while server.pending():
send_lines = server.sent(sock.send(server.pending()))
for line in send_lines:
while encoder.pending():
sent_lines = encoder.pop(sock.send(encoder.pending()))
for line in sent_lines:
print(f"> {line.format()}")
recv_lines = server.recv(sock.recv(1024))

View File

@ -1,7 +1,9 @@
from typing import List, Optional
from typing import Dict, List, Optional
from .tokens import ChanModes, Prefix
class ISupport(object):
raw: Dict[str, Optional[str]]
chanmodes = ChanModes(["b"], ["k"], ["l"], ["i", "m", "n", "p", "s", "t"])
prefix = Prefix(["o", "v"], ["@", "+"])
@ -9,9 +11,13 @@ class ISupport(object):
casemapping: str = "rfc1459"
chantypes: List[str] = ["#"]
def __init__(self):
self.raw = {}
def tokens(self, tokens: List[str]):
for token in tokens:
key, sep, value = token.partition("=")
self.raw[key] = value if sep else None
if key == "CHANMODES":
a, b, c, d = value.split(",")

View File

@ -31,7 +31,6 @@ class Server(Named):
self.modes: List[str] = []
self.motd: List[str] = []
self._encoder = StatefulEncoder()
self._decoder = StatefulDecoder()
self.users: Dict[str, User] = {}
@ -56,13 +55,6 @@ class Server(Named):
self.parse_tokens(line)
return lines
def send(self, line: Line):
self._encoder.push(line)
def pending(self) -> bytes:
return self._encoder.pending()
def sent(self, byte_count: int) -> List[Line]:
return self._encoder.pop(byte_count)
def parse_tokens(self, line: Line):
if line.command in LINE_HANDLERS:
for callback in LINE_HANDLERS[line.command]:
@ -205,7 +197,6 @@ class Server(Named):
self.channels.clear()
self.user_channels.clear()
self.channel_users.clear()
self._encoder.clear()
@line_handler("QUIT")
def handle_quit(self, line: Line):