Commit 40d4e496 authored by Julien Muchembled's avatar Julien Muchembled

Backward compatibility for Python 2.6

parent 2fb63515
...@@ -27,7 +27,7 @@ class Cache(object): ...@@ -27,7 +27,7 @@ class Cache(object):
q("CREATE INDEX volatile.stat_try ON stat(try)") q("CREATE INDEX volatile.stat_try ON stat(try)")
q("INSERT INTO volatile.stat (peer) SELECT prefix FROM peer") q("INSERT INTO volatile.stat (peer) SELECT prefix FROM peer")
self._db.commit() self._db.commit()
self._loadConfig(q("SELECT * FROM config")) self._loadConfig(self._selectConfig(q))
try: try:
cert.verifyVersion(self.version) cert.verifyVersion(self.version)
except (AttributeError, x509.VerifyError): except (AttributeError, x509.VerifyError):
...@@ -63,6 +63,11 @@ class Cache(object): ...@@ -63,6 +63,11 @@ class Cache(object):
"value") "value")
return db return db
@staticmethod
def _selectConfig(execute): # BBB: blob
return ((k, str(v) if type(v) is buffer else v)
for k, v in execute("SELECT * FROM config"))
def _loadConfig(self, config): def _loadConfig(self, config):
cls = self.__class__ cls = self.__class__
logging.debug("Loading network parameters:") logging.debug("Loading network parameters:")
...@@ -98,7 +103,7 @@ class Cache(object): ...@@ -98,7 +103,7 @@ class Cache(object):
old = {} old = {}
with self._db as db: with self._db as db:
remove = [] remove = []
for k, v in db.execute("SELECT * FROM config"): for k, v in self._selectConfig(db.execute):
if k in config: if k in config:
old[k] = v old[k] = v
continue continue
...@@ -109,8 +114,11 @@ class Cache(object): ...@@ -109,8 +114,11 @@ class Cache(object):
remove.append(k) remove.append(k)
db.execute("DELETE FROM config WHERE name in ('%s')" db.execute("DELETE FROM config WHERE name in ('%s')"
% "','".join(remove)) % "','".join(remove))
# BBB: Use buffer because of http://bugs.python.org/issue13676
# on Python 2.6
db.executemany("INSERT OR REPLACE INTO config VALUES(?,?)", db.executemany("INSERT OR REPLACE INTO config VALUES(?,?)",
config.iteritems()) ((k, buffer(v) if k in base64 else v)
for k, v in config.iteritems()))
self._loadConfig(config.iteritems()) self._loadConfig(config.iteritems())
return [k for k, v in config.iteritems() return [k for k, v in config.iteritems()
if k not in old or old[k] != v] if k not in old or old[k] != v]
......
...@@ -61,7 +61,7 @@ class RegistryServer(object): ...@@ -61,7 +61,7 @@ class RegistryServer(object):
"name TEXT PRIMARY KEY NOT NULL", "name TEXT PRIMARY KEY NOT NULL",
"value") "value")
self.prefix = self.getConfig("prefix", None) self.prefix = self.getConfig("prefix", None)
self.version = self.getConfig("version", "\0") self.version = str(self.getConfig("version", "\0")) # BBB: blob
utils.sqliteCreateTable(self.db, "token", utils.sqliteCreateTable(self.db, "token",
"token TEXT PRIMARY KEY NOT NULL", "token TEXT PRIMARY KEY NOT NULL",
"email TEXT NOT NULL", "email TEXT NOT NULL",
...@@ -129,7 +129,9 @@ class RegistryServer(object): ...@@ -129,7 +129,9 @@ class RegistryServer(object):
if config != self.getConfig('last_config', None): if config != self.getConfig('last_config', None):
self.version = self.encodeVersion( self.version = self.encodeVersion(
1 + self.decodeVersion(self.version)) 1 + self.decodeVersion(self.version))
self.setConfig('version', self.version) # BBB: Use buffer because of http://bugs.python.org/issue13676
# on Python 2.6
self.setConfig('version', buffer(self.version))
self.setConfig('last_config', config) self.setConfig('last_config', config)
self.sendto(self.prefix, 0) self.sendto(self.prefix, 0)
kw[''] = 'version', kw[''] = 'version',
......
...@@ -273,7 +273,7 @@ def main(): ...@@ -273,7 +273,7 @@ def main():
ipv4 = getattr(cache, 'ipv4', None) ipv4 = getattr(cache, 'ipv4', None)
if ipv4: if ipv4:
serial = int(cert.cert.get_subject().serialNumber) serial = int(cert.cert.get_subject().serialNumber)
if serial.bit_length() <= cache.ipv4_sublen <= 16: if cache.ipv4_sublen <= 16 and serial < 1 << cache.ipv4_sublen:
dot4 = lambda x: socket.inet_ntoa(struct.pack('!I', x)) dot4 = lambda x: socket.inet_ntoa(struct.pack('!I', x))
ip4('route', 'unreachable', ipv4, 'proto', 'static') ip4('route', 'unreachable', ipv4, 'proto', 'static')
ipv4, n = ipv4.split('/') ipv4, n = ipv4.split('/')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment