diff --git a/graphenebase/account.py b/graphenebase/account.py index 15d48489..82e2b5ec 100644 --- a/graphenebase/account.py +++ b/graphenebase/account.py @@ -452,8 +452,8 @@ def derive_from_seed(self, offset): order = ecdsa.SECP256k1.order secexp = (seed + z) % order secret = "%0x" % secexp - if len(secret) < 64: # left-pad with zeroes - secret = ("0" * (64-len(secret))) + secret + if len(secret) < 64: # left-pad with zeroes + secret = ("0" * (64 - len(secret))) + secret return PrivateKey(secret, prefix=self.pubkey.prefix) def __format__(self, _format): diff --git a/graphenebase/ecdsa.py b/graphenebase/ecdsa.py index 8233693b..ee4a22de 100644 --- a/graphenebase/ecdsa.py +++ b/graphenebase/ecdsa.py @@ -208,7 +208,7 @@ def sign_message(message, wif, hashfn=hashlib.sha256): sigder = bytearray(sigder) lenR = sigder[3] lenS = sigder[5 + lenR] - if lenR is 32 and lenS is 32: + if lenR == 32 and lenS == 32: # Derive the recovery parameter # i = recoverPubkeyParameter(message, digest, signature, public_key) @@ -254,7 +254,7 @@ def sign_message(message, wif, hashfn=hashlib.sha256): sigder = bytearray(sigder) lenR = sigder[3] lenS = sigder[5 + lenR] - if lenR is 32 and lenS is 32: + if lenR == 32 and lenS == 32: # Derive the recovery parameter # i = recoverPubkeyParameter( diff --git a/graphenestorage/sqlite.py b/graphenestorage/sqlite.py index edab327d..2274bc03 100644 --- a/graphenestorage/sqlite.py +++ b/graphenestorage/sqlite.py @@ -55,6 +55,7 @@ def __init__(self, *args, **kwargs): else: # pragma: no cover os.makedirs(data_dir) + class SQLiteCommon(object): """ This class abstracts away common sqlite3 operations. @@ -65,6 +66,7 @@ class SQLiteCommon(object): * ``sqlite_file``: Path to the SQLite Database file """ + def sql_fetchone(self, query): connection = sqlite3.connect(self.sqlite_file) try: @@ -91,7 +93,7 @@ def sql_execute(self, query, lastid=False): cursor = connection.cursor() cursor.execute(*query) connection.commit() - except: + except Exception: connection.close() raise ret = None @@ -142,10 +144,10 @@ def _haveKey(self, key): """ query = ( "SELECT {} FROM {} WHERE {}=?".format( - self.__value__, - self.__tablename__, - self.__key__ - ), (key,)) + self.__value__, self.__tablename__, self.__key__ + ), + (key,), + ) return True if self.sql_fetchone(query) else False def __setitem__(self, key, value): @@ -177,10 +179,10 @@ def __getitem__(self, key): """ query = ( "SELECT {} FROM {} WHERE {}=?".format( - self.__value__, - self.__tablename__, - self.__key__ - ), (key,)) + self.__value__, self.__tablename__, self.__key__ + ), + (key,), + ) result = self.sql_fetchone(query) if result: return result[0] @@ -196,15 +198,13 @@ def __iter__(self): return iter(self.keys()) def keys(self): - query = ("SELECT {} from {}".format( - self.__key__, - self.__tablename__), ) + query = ("SELECT {} from {}".format(self.__key__, self.__tablename__),) return [x[0] for x in self.sql_fetchall(query)] def __len__(self): """ return lenght of store """ - query = ("SELECT id from {}".format(self.__tablename__), ) + query = ("SELECT id from {}".format(self.__tablename__),) return len(self.sql_fetchall(query)) def __contains__(self, key): @@ -222,10 +222,11 @@ def __contains__(self, key): def items(self): """ returns all items off the store as tuples """ - query = ("SELECT {}, {} from {}".format( - self.__key__, - self.__value__, - self.__tablename__), ) + query = ( + "SELECT {}, {} from {}".format( + self.__key__, self.__value__, self.__tablename__ + ), + ) r = [] for key, value in self.sql_fetchall(query): r.append((key, value)) @@ -249,39 +250,37 @@ def delete(self, key): :param str value: Value """ query = ( - "DELETE FROM {} WHERE {}=?".format( - self.__tablename__, - self.__key__ - ), (key,)) + "DELETE FROM {} WHERE {}=?".format(self.__tablename__, self.__key__), + (key,), + ) self.sql_execute(query) def wipe(self): """ Wipe the store """ - query = ("DELETE FROM {}".format(self.__tablename__), ) + query = ("DELETE FROM {}".format(self.__tablename__),) self.sql_execute(query) def exists(self): """ Check if the database table exists """ - query = ("SELECT name FROM sqlite_master " + - "WHERE type='table' AND name=?", - (self.__tablename__, )) + query = ( + "SELECT name FROM sqlite_master " + "WHERE type='table' AND name=?", + (self.__tablename__,), + ) return True if self.sql_fetchone(query) else False def create(self): # pragma: no cover """ Create the new table in the SQLite database """ - query = (( - """ + query = ( + ( + """ CREATE TABLE {} ( id INTEGER PRIMARY KEY AUTOINCREMENT, {} STRING(256), {} STRING(256) )""" - ).format( - self.__tablename__, - self.__key__, - self.__value__ - ), ) + ).format(self.__tablename__, self.__key__, self.__value__), + ) self.sql_execute(query)