From 95241534a1aa2e73db8cffa18b982805579fe866 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Fri, 26 Sep 2025 05:03:55 +0200 Subject: [PATCH] Move IrcConnSetup attributes defaulting into Client.__init__, refactor cmd_connect. --- src/ircplom/client.py | 5 +++-- src/ircplom/client_tui.py | 30 +++++++++++------------------- src/test.txt | 6 +++--- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/ircplom/client.py b/src/ircplom/client.py index b6d0c24..63c6ed4 100644 --- a/src/ircplom/client.py +++ b/src/ircplom/client.py @@ -825,8 +825,9 @@ class Client(ABC, ClientQueueMixin): setattr(self.db, k, getattr(conn_setup, k)) if self.db.port <= 0: self.db.port = PORT_SSL - if not self.db.user_wanted: - self.db.user_wanted = getuser() + for attr_name in {'nick_wanted', 'user_wanted', 'realname'}: + if not getattr(self.db, attr_name): + setattr(self.db, attr_name, getuser()) def connect(self) -> None: 'Attempt to open connection, on success perform session init steps.' diff --git a/src/ircplom/client_tui.py b/src/ircplom/client_tui.py index 190d0dc..046bc7e 100644 --- a/src/ircplom/client_tui.py +++ b/src/ircplom/client_tui.py @@ -483,31 +483,23 @@ class ClientTui(BaseTui): def cmd__connect(self, host_port: str, nickname_pw: str = '', - username_realname: str = '' + realname_username: str = '' ) -> Optional[str]: 'Create Client and pass it via NewClientEvent.' - split = host_port.split(':', maxsplit=1) - hostname = split[0] + def from_split(input_: str) -> tuple[str, ...]: + return tuple(input_.split(':', maxsplit=1) if ':' in input_ + else (input_, '')) + hostname, port_str = from_split(host_port) if hostname in self._client_mngrs: return f'already set up connection to {hostname}' port = -1 - if len(split) > 1: - to_int = split[1] - if to_int.isdigit(): - port = int(split[1]) + if port_str: + if port_str.isdigit(): + port = int(port_str) else: - return f'invalid port number: {to_int}' - split = nickname_pw.split(':', maxsplit=1) - nickname = split[0] if nickname_pw else getuser() - password = split[1] if len(split) > 1 else '' - if not username_realname: - username = '' - realname = nickname - elif ':' in username_realname: - username, realname = username_realname.split(':', maxsplit=1) - else: - username = '' - realname = username_realname + return f'invalid port number: {port_str}' + nickname, password = from_split(nickname_pw) + realname, username = from_split(realname_username) setup = IrcConnSetup( hostname, port, nickname, username, realname, password) self._put(NewClientEvent(self._new_client(setup, set()))) diff --git a/src/test.txt b/src/test.txt index c691572..5371e01 100644 --- a/src/test.txt +++ b/src/test.txt @@ -16,7 +16,7 @@ # some simple expected command successes > /help 0 # commands available in this window: -0 # /connect HOST_PORT [NICKNAME_PW] [USERNAME_REALNAME] +0 # /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME] 0 # /help 0 # /list 0 # /prompt_enter @@ -43,7 +43,7 @@ # CONNECTED INTERACTIONS # on /connect init databases, log in new windows -> /connect foo.bar.baz foo:bar foobarbazquux:baz +> /connect foo.bar.baz foo:bar baz:foobarbazquux , $ DISCONNECTED 1 $ isupport cleared 1 $ isupport:CHANTYPES set to: [#&] @@ -168,7 +168,7 @@ > /window 1 > /help 1 # commands available in this window: -1 # /connect HOST_PORT [NICKNAME_PW] [USERNAME_REALNAME] +1 # /connect HOST_PORT [NICKNAME_PW] [REALNAME_USERNAME] 1 # /disconnect [QUIT_MSG] 1 # /help 1 # /join CHANNEL -- 2.30.2