From f2ada2ad57cef7eec0da84a04cd78a126ff47bc3 Mon Sep 17 00:00:00 2001 From: Filipe Pina Date: Mon, 19 Sep 2016 17:22:00 +0100 Subject: PEP8 + test.py --- miniircd | 12 ++++++++---- test.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/miniircd b/miniircd index 7ae4d37..8db1412 100755 --- a/miniircd +++ b/miniircd @@ -270,17 +270,21 @@ class Client(object): self.reply("331 %s %s :No topic is set" % (self.nickname, channel.name)) names_prefix = "353 %s = %s :" % (self.nickname, channelname) - names = names_prefix - # max length: reply prefix ":server_name(space)" plus CRLF in the end + names = '' + # max length: reply prefix ":server_name(space)" + # plus CRLF in the end names_max_len = 512 - (len(self.server.name) + 2 + 2) for name in sorted(x.nickname for x in channel.members): + if not names: + names = names_prefix + name # using >= to include the space between "names" and "name" - if len(names) + len(name) >= names_max_len: + elif len(names) + len(name) >= names_max_len: self.reply(names) names = names_prefix + name else: names += ' ' + name - self.reply(names) + if names: + self.reply(names) self.reply("366 %s %s :End of NAMES list" % (self.nickname, channelname)) diff --git a/test.py b/test.py index 3e3cd86..5069eb1 100644 --- a/test.py +++ b/test.py @@ -243,6 +243,60 @@ class TestBasicStuff(ServerFixture): self.expect("lemur", r":lemur!lemur@127.0.0.1 PART #fisk :boa") self.expect("apa", r":lemur!lemur@127.0.0.1 PART #fisk :boa") + def test_join_and_name_many_users(self): + base_nick = 'A' * 49 + # :FQDN 353 nick = #fisk : + base_len = len(socket.getfqdn()) + 66 + + one_line = (512 - base_len) / 50 + nick_list_one = [] + for i in range(one_line): + long_nick = '%s%d' % (base_nick, i) + nick_list_one.append(long_nick) + self.connect(long_nick) + self.send(long_nick, "JOIN #fisk") + self.expect( + long_nick, + r":%(nick)s!%(nick)s@127.0.0.1 JOIN #fisk" % { + 'nick': long_nick + } + ) + self.expect(long_nick, r":local\S+ 331 %s #fisk :.*" % long_nick) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_one) + ) + ) + self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick) + + nick_list_two = [] + for i in range(10 - one_line): + long_nick = '%s%d' % (base_nick, one_line + i) + nick_list_two.append(long_nick) + self.connect(long_nick) + self.send(long_nick, "JOIN #fisk") + self.expect( + long_nick, + r":%(nick)s!%(nick)s@127.0.0.1 JOIN #fisk" % { + 'nick': long_nick + } + ) + self.expect(long_nick, r":local\S+ 331 %s #fisk :.*" % long_nick) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_one) + ) + ) + self.expect( + long_nick, + r":local\S+ 353 %s = #fisk :%s" % ( + long_nick, ' '.join(nick_list_two) + ) + ) + self.expect(long_nick, r":local\S+ 366 %s #fisk :.*" % long_nick) + def test_ison(self): self.connect("apa") self.send("apa", "ISON apa lemur") -- cgit v1.2.3