mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
Rename cdb.open to cdb.open_db and open cdb files in binary mode.
This commit is contained in:
parent
709c3390ef
commit
14200e002a
14
src/cdb.py
14
src/cdb.py
@ -60,7 +60,7 @@ def dump(map, fd=sys.stdout):
|
|||||||
for (key, value) in map.iteritems():
|
for (key, value) in map.iteritems():
|
||||||
fd.write('+%s,%s:%s->%s\n' % (len(key), len(value), key, value))
|
fd.write('+%s,%s:%s->%s\n' % (len(key), len(value), key, value))
|
||||||
|
|
||||||
def open(filename, mode='r', **kwargs):
|
def open_db(filename, mode='r', **kwargs):
|
||||||
"""Opens a database; used for compatibility with other database modules."""
|
"""Opens a database; used for compatibility with other database modules."""
|
||||||
if mode == 'r':
|
if mode == 'r':
|
||||||
return Reader(filename, **kwargs)
|
return Reader(filename, **kwargs)
|
||||||
@ -114,7 +114,7 @@ def make(dbFilename, readFilename=None):
|
|||||||
if readFilename is None:
|
if readFilename is None:
|
||||||
readfd = sys.stdin
|
readfd = sys.stdin
|
||||||
else:
|
else:
|
||||||
readfd = file(readFilename, 'r')
|
readfd = open(readFilename, 'rb')
|
||||||
maker = Maker(dbFilename)
|
maker = Maker(dbFilename)
|
||||||
while 1:
|
while 1:
|
||||||
(initchar, key, value) = _readKeyValue(readfd)
|
(initchar, key, value) = _readKeyValue(readfd)
|
||||||
@ -129,7 +129,7 @@ def make(dbFilename, readFilename=None):
|
|||||||
class Maker(object):
|
class Maker(object):
|
||||||
"""Class for making CDB databases."""
|
"""Class for making CDB databases."""
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.fd = utils.file.AtomicFile(filename)
|
self.fd = utils.file.AtomicFile(filename, 'wb')
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.fd.seek(2048)
|
self.fd.seek(2048)
|
||||||
self.hashPointers = [(0, 0)] * 256
|
self.hashPointers = [(0, 0)] * 256
|
||||||
@ -182,7 +182,7 @@ class Reader(utils.IterableMap):
|
|||||||
"""Class for reading from a CDB database."""
|
"""Class for reading from a CDB database."""
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.fd = file(filename, 'r')
|
self.fd = open(filename, 'rb')
|
||||||
self.loop = 0
|
self.loop = 0
|
||||||
self.khash = 0
|
self.khash = 0
|
||||||
self.kpos = 0
|
self.kpos = 0
|
||||||
@ -292,7 +292,7 @@ class ReaderWriter(utils.IterableMap):
|
|||||||
|
|
||||||
def _openFiles(self):
|
def _openFiles(self):
|
||||||
self.cdb = Reader(self.filename)
|
self.cdb = Reader(self.filename)
|
||||||
self.journal = file(self.journalName, 'w')
|
self.journal = open(self.journalName, 'wb')
|
||||||
|
|
||||||
def _closeFiles(self):
|
def _closeFiles(self):
|
||||||
self.cdb.close()
|
self.cdb.close()
|
||||||
@ -312,7 +312,7 @@ class ReaderWriter(utils.IterableMap):
|
|||||||
removals = set()
|
removals = set()
|
||||||
adds = {}
|
adds = {}
|
||||||
try:
|
try:
|
||||||
fd = file(self.journalName, 'r')
|
fd = open(self.journalName, 'rb')
|
||||||
while 1:
|
while 1:
|
||||||
(initchar, key, value) = _readKeyValue(fd)
|
(initchar, key, value) = _readKeyValue(fd)
|
||||||
if initchar is None:
|
if initchar is None:
|
||||||
@ -457,7 +457,7 @@ class Shelf(ReaderWriter):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if sys.argv[0] == 'cdbdump':
|
if sys.argv[0] == 'cdbdump':
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
fd = file(sys.argv[1], 'r')
|
fd = open(sys.argv[1], 'rb')
|
||||||
else:
|
else:
|
||||||
fd = sys.stdin
|
fd = sys.stdin
|
||||||
db = Reader(fd)
|
db = Reader(fd)
|
||||||
|
16
src/conf.py
16
src/conf.py
@ -91,7 +91,7 @@ def registerChannelValue(group, name, value):
|
|||||||
value.channelValue = True
|
value.channelValue = True
|
||||||
g = group.register(name, value)
|
g = group.register(name, value)
|
||||||
gname = g._name.lower()
|
gname = g._name.lower()
|
||||||
for name in registry._cache.iterkeys():
|
for name in registry._cache.keys():
|
||||||
if name.lower().startswith(gname) and len(gname) < len(name):
|
if name.lower().startswith(gname) and len(gname) < len(name):
|
||||||
name = name[len(gname)+1:] # +1 for .
|
name = name[len(gname)+1:] # +1 for .
|
||||||
parts = registry.split(name)
|
parts = registry.split(name)
|
||||||
@ -187,7 +187,7 @@ class ValidChannel(registry.String):
|
|||||||
def error(self):
|
def error(self):
|
||||||
try:
|
try:
|
||||||
super(ValidChannel, self).error()
|
super(ValidChannel, self).error()
|
||||||
except registry.InvalidRegistryValue, e:
|
except registry.InvalidRegistryValue as e:
|
||||||
e.channel = self.channel
|
e.channel = self.channel
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ class Servers(registry.SpaceSeparatedListOfStrings):
|
|||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
L = registry.SpaceSeparatedListOfStrings.__call__(self)
|
L = registry.SpaceSeparatedListOfStrings.__call__(self)
|
||||||
return map(self.convert, L)
|
return list(map(self.convert, L))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return ' '.join(registry.SpaceSeparatedListOfStrings.__call__(self))
|
return ' '.join(registry.SpaceSeparatedListOfStrings.__call__(self))
|
||||||
@ -259,7 +259,7 @@ class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
|
|||||||
List = ircutils.IrcSet
|
List = ircutils.IrcSet
|
||||||
Value = ValidChannel
|
Value = ValidChannel
|
||||||
def join(self, channel):
|
def join(self, channel):
|
||||||
import ircmsgs # Don't put this globally! It's recursive.
|
from . import ircmsgs # Don't put this globally! It's recursive.
|
||||||
key = self.key.get(channel)()
|
key = self.key.get(channel)()
|
||||||
if key:
|
if key:
|
||||||
return ircmsgs.join(channel, key)
|
return ircmsgs.join(channel, key)
|
||||||
@ -300,7 +300,7 @@ def registerNetwork(name, password='', ssl=False, sasl_username='',
|
|||||||
return network
|
return network
|
||||||
|
|
||||||
# Let's fill our networks.
|
# Let's fill our networks.
|
||||||
for (name, s) in registry._cache.iteritems():
|
for (name, s) in registry._cache.items():
|
||||||
if name.startswith('supybot.networks.'):
|
if name.startswith('supybot.networks.'):
|
||||||
parts = name.split('.')
|
parts = name.split('.')
|
||||||
name = parts[2]
|
name = parts[2]
|
||||||
@ -901,7 +901,7 @@ class CDB(registry.Boolean):
|
|||||||
import supybot.cdb as cdb
|
import supybot.cdb as cdb
|
||||||
basename = os.path.basename(filename)
|
basename = os.path.basename(filename)
|
||||||
journalName = supybot.directories.data.tmp.dirize(basename+'.journal')
|
journalName = supybot.directories.data.tmp.dirize(basename+'.journal')
|
||||||
return cdb.open(filename, 'c',
|
return cdb.open_db(filename, 'c',
|
||||||
journalName=journalName,
|
journalName=journalName,
|
||||||
maxmods=self.maximumModifications())
|
maxmods=self.maximumModifications())
|
||||||
|
|
||||||
@ -944,7 +944,7 @@ class Banmask(registry.SpaceSeparatedSetOfStrings):
|
|||||||
self.__parent = super(Banmask, self)
|
self.__parent = super(Banmask, self)
|
||||||
self.__parent.__init__(*args, **kwargs)
|
self.__parent.__init__(*args, **kwargs)
|
||||||
self.__doc__ = format('Valid values include %L.',
|
self.__doc__ = format('Valid values include %L.',
|
||||||
map(repr, self.validStrings))
|
list(map(repr, self.validStrings)))
|
||||||
|
|
||||||
def help(self):
|
def help(self):
|
||||||
strings = [s for s in self.validStrings if s]
|
strings = [s for s in self.validStrings if s]
|
||||||
@ -960,7 +960,7 @@ class Banmask(registry.SpaceSeparatedSetOfStrings):
|
|||||||
return self.validStrings[i]
|
return self.validStrings[i]
|
||||||
|
|
||||||
def setValue(self, v):
|
def setValue(self, v):
|
||||||
v = map(self.normalize, v)
|
v = list(map(self.normalize, v))
|
||||||
for s in v:
|
for s in v:
|
||||||
if s not in self.validStrings:
|
if s not in self.validStrings:
|
||||||
self.error()
|
self.error()
|
||||||
|
@ -280,7 +280,7 @@ class CdbMapping(MappingInterface):
|
|||||||
self.db['nextId'] = '1'
|
self.db['nextId'] = '1'
|
||||||
|
|
||||||
def _openCdb(self, *args, **kwargs):
|
def _openCdb(self, *args, **kwargs):
|
||||||
self.db = cdb.open(self.filename, 'c', **kwargs)
|
self.db = cdb.open_db(self.filename, 'c', **kwargs)
|
||||||
|
|
||||||
def _getNextId(self):
|
def _getNextId(self):
|
||||||
i = int(self.db['nextId'])
|
i = int(self.db['nextId'])
|
||||||
|
Loading…
Reference in New Issue
Block a user