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