py3: raise exceptions using six module

There is no other way to make Python2 and Python3 happy, because syntax
raise E, V, T is incompatible with the latter.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Łukasz Żarnowiecki
2016-05-17 19:56:52 +02:00
committed by Nicolas Sebrecht
parent 83539f8601
commit 0addcbabf0
13 changed files with 70 additions and 49 deletions

View File

@ -17,6 +17,9 @@
import os
from sys import exc_info
from threading import Lock
import six
try:
import sqlite3 as sqlite
except:
@ -68,15 +71,15 @@ class LocalStatusSQLiteFolder(BaseFolder):
self.connection = sqlite.connect(self.filename, check_same_thread=False)
except NameError:
# sqlite import had failed.
raise UserWarning("SQLite backend chosen, but cannot connect "
six.reraise(UserWarning("SQLite backend chosen, but cannot connect "
"with available bindings to '%s'. Is the sqlite3 package "
"installed?."% self.filename), None, exc_info()[2]
"installed?."% self.filename), None, exc_info()[2])
except sqlite.OperationalError as e:
# Operation had failed.
raise UserWarning("cannot open database file '%s': %s.\nYou might "
six.reraise(UserWarning("cannot open database file '%s': %s.\nYou might "
"want to check the rights to that file and if it cleanly opens "
"with the 'sqlite<3>' command."%
(self.filename, e)), None, exc_info()[2]
(self.filename, e)), None, exc_info()[2])
# Make sure sqlite is in multithreading SERIALIZE mode.
assert sqlite.threadsafety == 1, 'Your sqlite is not multithreading safe.'