Skip to content

Commit

Permalink
Fix build in py3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Jun 23, 2020
1 parent 493d2dd commit 9482b98
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions graphenebase/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions graphenebase/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
63 changes: 31 additions & 32 deletions graphenestorage/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -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):
Expand All @@ -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))
Expand All @@ -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)

0 comments on commit 9482b98

Please sign in to comment.