mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made isIP actually test properly and added tests.
This commit is contained in:
parent
c1dd8204f8
commit
227f6e1e53
@ -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.
|
||||||
|
@ -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'))
|
||||||
|
Loading…
Reference in New Issue
Block a user