Made isIP actually test properly and added tests.

This commit is contained in:
Jeremy Fincher 2003-04-10 07:36:49 +00:00
parent c1dd8204f8
commit 227f6e1e53
2 changed files with 15 additions and 1 deletions

View File

@ -105,7 +105,17 @@ def isIP(s):
>>> isIP('abc.abc.abc.abc') >>> isIP('abc.abc.abc.abc')
0 0
""" """
return (s.translate(string.ascii, _ipchars) == "") if s.translate(string.ascii, _ipchars) == '':
quads = s.split('.')
if len(quads) <= 4:
for quad in quads:
if int(quad) >= 256:
return False
return True
else:
return False
else:
return False
def banmask(hostmask): def banmask(hostmask):
"""Returns a properly generic banning hostmask for a hostmask. """Returns a properly generic banning hostmask for a hostmask.

View File

@ -79,7 +79,11 @@ class FunctionsTestCase(unittest.TestCase):
def testIsIP(self): def testIsIP(self):
self.failIf(ircutils.isIP('a.b.c')) self.failIf(ircutils.isIP('a.b.c'))
self.failIf(ircutils.isIP('256.0.0.0'))
self.failUnless(ircutils.isIP('127.1'))
self.failUnless(ircutils.isIP('0.0.0.0'))
self.failUnless(ircutils.isIP('100.100.100.100')) self.failUnless(ircutils.isIP('100.100.100.100'))
self.failUnless(ircutils.isIP('255.255.255.255'))
def testIsNick(self): def testIsNick(self):
self.failUnless(ircutils.isNick('jemfinch')) self.failUnless(ircutils.isNick('jemfinch'))