mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Fix for bug #998311; we should now work fine with channels with dots in their names.
This commit is contained in:
parent
7b07de9fcd
commit
3234af10e7
@ -68,7 +68,9 @@ def open(filename, clear=False):
|
||||
for (i, line) in enumerate(fd):
|
||||
line = line.rstrip('\r\n')
|
||||
try:
|
||||
(key, value) = re.split(r':\s*', line, 1)
|
||||
(key, value) = re.split(r'(?<!\\):', line, 1)
|
||||
key = key.strip()
|
||||
value = value.strip()
|
||||
except ValueError:
|
||||
raise InvalidRegistryFile, 'Error unpacking line #%s' % (i+1)
|
||||
_cache[key] = value
|
||||
@ -103,21 +105,34 @@ def close(registry, filename, annotated=True, helpOnceOnly=False):
|
||||
lines.append('###\n')
|
||||
fd.writelines(lines)
|
||||
if hasattr(value, 'value'): # This lets us print help for non-valued.
|
||||
fd.write('%s: %s\n' % (escape(name), value))
|
||||
fd.write('%s: %s\n' % (name, value))
|
||||
fd.close()
|
||||
|
||||
def isValidRegistryName(name):
|
||||
return '.' not in name and ':' not in name and len(name.split()) == 1
|
||||
# Now we can have . and : in names. I'm still gonna call shenanigans on
|
||||
# anyone who tries to have spaces (though technically I can't see any
|
||||
# reason why it wouldn't work).
|
||||
return len(name.split()) == 1
|
||||
|
||||
def escape(name):
|
||||
name = name.replace('\\', '\\\\')
|
||||
name = name.replace(':', '\\:')
|
||||
name = name.replace('.', '\\.')
|
||||
return name
|
||||
|
||||
def unescape(name):
|
||||
name = name.replace('\\.', '.')
|
||||
name = name.replace('\\:', ':')
|
||||
name = name.replace('\\\\', '\\')
|
||||
return name
|
||||
|
||||
_splitRe = re.compile(r'(?<!\\)\.')
|
||||
def split(name):
|
||||
# XXX: This should eventually handle escapes.
|
||||
return name.split('.')
|
||||
return map(unescape, _splitRe.split(name))
|
||||
|
||||
def join(names):
|
||||
return '.'.join(names)
|
||||
return '.'.join(map(escape, names))
|
||||
|
||||
class Group(object):
|
||||
def __init__(self, supplyDefault=False):
|
||||
@ -168,8 +183,10 @@ class Group(object):
|
||||
return self.__getattr__(attr)
|
||||
|
||||
def setName(self, name):
|
||||
#print '***', name
|
||||
self._name = name
|
||||
if name in _cache and self._lastModified < _lastModified:
|
||||
#print '***>', _cache[name]
|
||||
self.set(_cache[name])
|
||||
if self.supplyDefault:
|
||||
for (k, v) in _cache.iteritems():
|
||||
@ -189,7 +206,9 @@ class Group(object):
|
||||
if name not in self.children: # XXX Is this right?
|
||||
self.children[name] = node
|
||||
self.added.append(name)
|
||||
fullname = join([self._name, name])
|
||||
names = split(self._name)
|
||||
names.append(name)
|
||||
fullname = join(names)
|
||||
node.setName(fullname)
|
||||
return node
|
||||
|
||||
|
@ -36,6 +36,43 @@ import re
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
|
||||
join = registry.join
|
||||
split = registry.split
|
||||
escape = registry.escape
|
||||
unescape = registry.unescape
|
||||
class FunctionsTestCase(SupyTestCase):
|
||||
def testEscape(self):
|
||||
self.assertEqual('foo', escape('foo'))
|
||||
self.assertEqual('foo\\.bar', escape('foo.bar'))
|
||||
self.assertEqual('foo\\:bar', escape('foo:bar'))
|
||||
|
||||
def testUnescape(self):
|
||||
self.assertEqual('foo', unescape('foo'))
|
||||
self.assertEqual('foo.bar', unescape('foo\\.bar'))
|
||||
self.assertEqual('foo:bar', unescape('foo\\:bar'))
|
||||
|
||||
def testEscapeAndUnescapeAreInverses(self):
|
||||
for s in ['foo', 'foo.bar']:
|
||||
self.assertEqual(s, unescape(escape(s)))
|
||||
self.assertEqual(escape(s), escape(unescape(escape(s))))
|
||||
|
||||
def testSplit(self):
|
||||
self.assertEqual(['foo'], split('foo'))
|
||||
self.assertEqual(['foo', 'bar'], split('foo.bar'))
|
||||
self.assertEqual(['foo.bar'], split('foo\\.bar'))
|
||||
|
||||
def testJoin(self):
|
||||
self.assertEqual('foo', join(['foo']))
|
||||
self.assertEqual('foo.bar', join(['foo', 'bar']))
|
||||
self.assertEqual('foo\\.bar', join(['foo.bar']))
|
||||
|
||||
def testJoinAndSplitAreInverses(self):
|
||||
for s in ['foo', 'foo.bar', 'foo\\.bar']:
|
||||
self.assertEqual(s, join(split(s)))
|
||||
self.assertEqual(split(s), split(join(split(s))))
|
||||
|
||||
|
||||
|
||||
class ValuesTestCase(SupyTestCase):
|
||||
def testBoolean(self):
|
||||
v = registry.Boolean(True, """Help""")
|
||||
|
Loading…
Reference in New Issue
Block a user