mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +01:00
Added dccIP and unDccIP.
This commit is contained in:
parent
fc24f3ded1
commit
155aeebe42
@ -313,6 +313,25 @@ def shrinkList(L, sep='', limit=425):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def dccIP(ip):
|
||||
"""Returns in IP in the proper for DCC."""
|
||||
assert isIP(ip), 'argument must be a string ip in xxx.yyy.zzz.www format.'
|
||||
i = 0
|
||||
x = 256**3
|
||||
for quad in ip.split('.'):
|
||||
i += int(quad)*x
|
||||
x /= 256
|
||||
return i
|
||||
|
||||
def unDccIP(i):
|
||||
"""Takes an integer DCC IP and return a normal string IP."""
|
||||
assert isinstance(i, (int, long)), '%r is not an number.' % i
|
||||
L = []
|
||||
while len(L) < 4:
|
||||
L.insert(0, i % 256)
|
||||
i /= 256
|
||||
return '.'.join(map(str, L))
|
||||
|
||||
|
||||
class IrcString(str):
|
||||
"""This class does case-insensitive comparison and hashing of nicks."""
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
from test import *
|
||||
|
||||
import random
|
||||
|
||||
import ircmsgs
|
||||
import ircutils
|
||||
|
||||
@ -141,13 +143,6 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.assertEqual('jemfinch', ircutils.toLower('jemfinch'))
|
||||
self.assertEqual('{}|^', ircutils.toLower('[]\\~'))
|
||||
|
||||
## def testNick(self):
|
||||
## nicks = ['jemfinch', 'jemfinch\\[]~']
|
||||
## for nick in nicks:
|
||||
## self.assertEqual(str(ircutils.nick(nick)), str(nick))
|
||||
## self.assertEqual(ircutils.nick(nick), nick)
|
||||
## self.assertEqual(ircutils.nick(nick), ircutils.toLower(nick))
|
||||
|
||||
def testReplyTo(self):
|
||||
prefix = 'foo!bar@baz'
|
||||
channel = ircmsgs.privmsg('#foo', 'bar baz', prefix=prefix)
|
||||
@ -170,6 +165,15 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x03'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312foo\x0F'), 'foo')
|
||||
self.assertEqual(ircutils.unColor('\x0312,14foo\x0F'), 'foo')
|
||||
|
||||
def testDccIpStuff(self):
|
||||
def randomIP():
|
||||
def rand():
|
||||
return random.randrange(0, 256)
|
||||
return '.'.join(map(str, [rand(), rand(), rand(), rand()]))
|
||||
for _ in range(100): # 100 should be good :)
|
||||
ip = randomIP()
|
||||
self.assertEqual(ip, ircutils.unDccIP(ircutils.dccIP(ip)))
|
||||
|
||||
|
||||
class IrcDictTestCase(unittest.TestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user