4141
4242class IRCv3Connection :
4343 """Connects to an IRC server at the given address."""
44- def __init__ (self , hostname , nick , username , realname , ipv6 = False , debug = False ):
44+ def __init__ (self , hostname , nick , username , realname , ipv6 = False , debug = False , exit_early = False ):
4545 self .debug = debug
46+ self .exit_early = exit_early
4647 self ._data = b''
4748
4849 if ipv6 :
@@ -61,6 +62,8 @@ def __init__(self, hostname, nick, username, realname, ipv6=False, debug=False):
6162 self .send ('CAP LS 302' )
6263 self .send ('NICK {}' .format (nick ))
6364 self .send ('USER {} 0 * :{}' .format (username , realname ))
65+ if exit_early :
66+ self .send ('QUIT' )
6467 self .send ('CAP END' )
6568
6669 # events setup
@@ -74,7 +77,7 @@ def __init__(self, hostname, nick, username, realname, ipv6=False, debug=False):
7477 # basic data
7578 self .caps = {}
7679 self .isupport = {}
77-
80+
7881 def loop (self ):
7982 """Start connection loop."""
8083 try :
@@ -142,38 +145,60 @@ def on_connected(self, msg):
142145def check_net (versions , info ):
143146 print ("Connecting to:" , info ['name' ])
144147 hostname = info ['net-address' ]['display' ]
148+ exit_early = info ['net-address' ].get ('exit-early' , False )
145149
146150 supported = {}
147151
148- irc = IRCv3Connection (hostname , nick , username , realname , debug = False )
152+ irc = IRCv3Connection (hostname , nick , username , realname , debug = False , exit_early = exit_early )
149153 irc .loop ()
150154
151- supported ['features ' ] = irc .isupport .keys ()
155+ supported ['isupport ' ] = irc .isupport .keys ()
152156 supported ['caps' ] = irc .caps .keys ()
153157
154- # generate cap lists
158+ # generate cap and isupport lists
155159 all_caps = []
160+ all_isupport = []
156161 for ver in versions :
157162 for spec in versions [ver ]['specs' ]:
158163 all_caps .extend (versions [ver ]['specs' ][spec ].get ('caps' , []))
159-
160- claimed_supported = []
161- for ver in info ['support' ]:
162- for spec in info ['support' ][ver ]:
163- claimed_supported .extend (versions [ver ]['specs' ][spec ].get ('caps' , []))
164-
165- claimed_unsupported = []
164+ all_isupport .extend (versions [ver ]['specs' ][spec ].get ('isupport' , []))
165+
166+ claimed_supported_caps = []
167+ claimed_supported_isupport = []
168+ for suptype in ['support' , 'partial' ]:
169+ if suptype not in info :
170+ continue
171+ for ver in info [suptype ]:
172+ for spec in info [suptype ][ver ]:
173+ claimed_supported_caps .extend (versions [ver ]['specs' ][spec ].get ('caps' , []))
174+ claimed_supported_isupport .extend (versions [ver ]['specs' ][spec ].get ('isupport' , []))
175+
176+ claimed_unsupported_caps = []
177+ claimed_unsupported_isupport = []
166178 for cap in all_caps :
167- if cap not in claimed_supported :
168- claimed_unsupported .append (cap )
179+ if cap not in claimed_supported_caps :
180+ claimed_unsupported_caps .append (cap )
181+ for key in all_isupport :
182+ if key not in claimed_supported_isupport :
183+ claimed_unsupported_isupport .append (key )
169184
170185 # and check them
171- for cap in claimed_supported :
186+ for cap in claimed_supported_caps :
172187 if cap not in supported ['caps' ]:
173- print (' *!* - ' , info ['name' ], 'claims to support ' , cap , 'but does not' )
174- for cap in claimed_unsupported :
188+ print (' *!* - ' , info ['name' ], 'claims to advertise cap ' , cap , 'but does not' )
189+ for cap in claimed_unsupported_caps :
175190 if cap in supported ['caps' ]:
176- print (' *!* + ' , info ['name' ], 'now also supports' , cap )
191+ print (' *!* + ' , info ['name' ], 'now also sadvertise cap' , cap )
192+ if exit_early :
193+ # we didn't get to see isupport tokens, skip checking those
194+ return
195+
196+ for token in claimed_supported_isupport :
197+ if token not in supported ['isupport' ]:
198+ print (' *!* - ' , info ['name' ], 'claims to advertise isupport token' , token , 'but does not' )
199+ for token in claimed_unsupported_isupport :
200+ if token in supported ['isupport' ]:
201+ print (' *!* + ' , info ['name' ], 'now also sadvertise isupport token' , token )
177202
178203if __name__ == '__main__' :
179204 arguments = docopt (__doc__ , version = '0.0.1' )
0 commit comments