return bool(inserts)
def split_server_put_and_log(line: str, **_) -> list[str]:
- context, msg = line.split(_CHAR_CONTEXT_SEP, maxsplit=1)
+ context, msg = self._split_by_context_separator(line)
assert msg[0] in '.*' and msg[1:3] == f'{LOG_PREFIX_IN} '
c_id, win_ids = context[1:].split(_CHAR_ID_TYPE_SEP, maxsplit=1)
return [f'{_CHAR_SERVER_MSG}{c_id}{_CHAR_CONTEXT_SEP}{msg[3:]}',
if len(range_data) == 2:
return inserts
for jdx, insert in enumerate(inserts):
- if (result := self._split_active_line(insert)):
- inserts[jdx] = _CHAR_CONTEXT_SEP.join([range_data[2]]
- + [result[1]])
+ context, msg = self._split_by_context_separator(insert)
+ if context == _CHAR_ANCHOR:
+ continue
+ inserts[jdx] = _CHAR_CONTEXT_SEP.join([range_data[2]] + [msg])
return inserts
while expand_parsed(_CHAR_ID_TYPE_SEP, split_server_put_and_log):
anchors: dict[str, int] = {}
for idx, line in enumerate(self._lines):
if line[:1] == _CHAR_ANCHOR:
- anchors[line[1:]] = idx
+ anchors[line[2:]] = idx
if not expand_parsed(_TOK_REPEAT, repeat, anchors=anchors):
break
self._lines = [ln for ln in self._lines
def next_log(self) -> tuple[int, tuple[int, ...], str]:
'Return index, win IDs, and context of next expected log line.'
- context, msg = self._current_line.split(_CHAR_CONTEXT_SEP, maxsplit=1)
+ context, msg = self._split_by_context_separator(self._current_line)
if _CHAR_RANGE in context:
_, context = context.split(_CHAR_RANGE)
expected_win_ids = tuple(
def _play_till_log(self) -> None:
while True:
- if (result := self._split_active_line(self._current_line)):
- context, msg = result
- if context == _CHAR_PROMPT:
- assert self.put_keypress is not None
- for c in msg:
- self.put_keypress(c)
- self.put_keypress('KEY_ENTER')
- elif context.startswith(_CHAR_SERVER_MSG):
- client = self._get_client(int(context[1:]))
- assert isinstance(client.conn, _FakeIrcConnection)
- client.conn.put_server_msg(msg)
- else:
- break
+ context, msg = self._split_by_context_separator(self._current_line)
+ if context == _CHAR_PROMPT:
+ assert self.put_keypress is not None
+ for c in msg:
+ self.put_keypress(c)
+ self.put_keypress('KEY_ENTER')
+ elif context.startswith(_CHAR_SERVER_MSG):
+ client = self._get_client(int(context[1:]))
+ assert isinstance(client.conn, _FakeIrcConnection)
+ client.conn.put_server_msg(msg)
+ else:
+ break
self._idx += 1
@staticmethod
- def _split_active_line(line: str) -> Optional[tuple[str, ...]]:
- 'Return 2-items tuple of split line, or None if empty/comment/anchor.'
- if _CHAR_CONTEXT_SEP not in line:
- return None
+ def _split_by_context_separator(line: str) -> tuple[str, ...]:
+ 'Return two-items tuple of CHAR_CONTEXT_SEP-split line, or None.'
return tuple(line.split(_CHAR_CONTEXT_SEP, maxsplit=1))
# on /connect init databases, log in new windows
> /connect foo.bar.baz foo:bar baz:foobarbazquux
-|standard-clears-in
-|isupport-clear-in
+| standard-clears-in
+| isupport-clear-in
1 .$ isupport cleared
1 .$ isupport:CHANTYPES set to: [#&]
1 .$ isupport:PREFIX set to: [(ov)@+]
1 .$ isupport:USERLEN set to: [10]
-|isupport-clear-out
+| isupport-clear-out
1 .$ caps cleared
1 .$ users cleared
1 .$ channels cleared
-|standard-clears-out
+| standard-clears-out
, .$ DISCONNECTED
# connect with values set by /connect, init CAP negotation
1 .$ realname set to: [baz]
1 .$ password set to: [bar]
1 .$ port set to: [6697]
-|conn0
+| conn0
1 .$ connection_state set to: [connecting]
1 .$ connection_state set to: [connected]
-|conn1
+| conn1
, .$ CONNECTED
-|conn2
+| conn2
1 .> CAP LS :302
1 .> USER foobarbazquux 0 * :baz
1 .> NICK :foo
# of all pre-MOTD greeting messages, only process isupports
:0:1 .< :foo.bar.baz 001 foo1 :Welcome to the foo.bar.baz network
-|conn3
+| conn3
:0:1 .< :foo.bar.baz 002 foo1 :Your host is foo.bar.baz
:0:1 .< :foo.bar.baz 003 foo1 :This server was created Jan 1 2020
:0:1 .< :foo.bar.baz 004 foo1 foo.bar.baz ircserver-1.0 abc def ghi
# handle bot query NOTICE
:0:1 .< :SaslServ!SaslServ@services.bar.baz NOTICE foo1 :Last login from ~foobarbaz@foo.bar.baz on Jan 1 22:00:00 2021 +0000.
3 .< *** [SaslServ] Last login from ~foobarbaz@foo.bar.baz on Jan 1 22:00:00 2021 +0000.
-|conn4
+| conn4
# check difference in available commands when switching to client window
> /join #test
0 .# 1) foo.bar.baz :DEBUG
0 .# 2) foo.bar.baz server
0 .# 3) foo.bar.baz SaslServ
-|conn5
+| conn5
> /window 1
> /help
1 .# commands available in this window:
1 .!$ cannot send, connection seems closed
> /privmsg #test test
1 .!$ not sending, since not in channel
-|conn6
+| conn6
# test setting up second client, but 432 irrecoverably
> /connect baz.bar.foo ?foo foo:foo