From 012ee334991257a23589b92627a872b62237e222 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 26 Mar 2020 03:57:54 -0500 Subject: [PATCH] corrected onionrstorage formatting --- src/onionrstorage/__init__.py | 14 ++++++-------- src/onionrstorage/removeblock.py | 13 +++++++------ src/onionrstorage/setdata.py | 22 +++++++++++++++------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/onionrstorage/__init__.py b/src/onionrstorage/__init__.py index 7e198663..27ef8ccd 100755 --- a/src/onionrstorage/__init__.py +++ b/src/onionrstorage/__init__.py @@ -1,8 +1,8 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication. - This file handles block storage, providing an abstraction for storing blocks between file system and database -''' +Handle block storage, providing an abstraction for +storing blocks between file system and database +""" import sys import sqlite3 import os @@ -10,12 +10,10 @@ from onionrutils import bytesconverter from onionrutils import stringvalidators from coredb import dbfiles import filepaths -import onionrcrypto import onionrexceptions -from onionrsetup import dbcreator from onionrcrypto import hashers from . import setdata -''' +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -28,7 +26,7 @@ from . import setdata You should have received a copy of the GNU General Public License along with this program. If not, see . -''' +""" DB_ENTRY_SIZE_LIMIT = 10000 # Will be a config option diff --git a/src/onionrstorage/removeblock.py b/src/onionrstorage/removeblock.py index 49ec846f..b2f0cc78 100644 --- a/src/onionrstorage/removeblock.py +++ b/src/onionrstorage/removeblock.py @@ -2,8 +2,11 @@ remove onionr block from meta db """ -import sys, sqlite3 -import onionrexceptions, onionrstorage +import sys +import sqlite3 + +import onionrexceptions +import onionrstorage from onionrutils import stringvalidators from coredb import dbfiles from onionrblocks import storagecounter @@ -24,12 +27,10 @@ from onionrblocks import storagecounter def remove_block(block): - """ - remove a block from this node (does not automatically blacklist) + """remove a block from this node (does not automatically blacklist). - **You may want blacklist.addToDB(blockHash) + **You may want blacklist.addToDB(blockHash) """ - if stringvalidators.validate_hash(block): conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30) c = conn.cursor() diff --git a/src/onionrstorage/setdata.py b/src/onionrstorage/setdata.py index cbff6e21..e742ff7e 100644 --- a/src/onionrstorage/setdata.py +++ b/src/onionrstorage/setdata.py @@ -5,7 +5,9 @@ Test Onionr as it is running import sys import sqlite3 -import onionrstorage, onionrexceptions, onionrcrypto as crypto +import onionrstorage +import onionrexceptions +import onionrcrypto as crypto import filepaths from onionrblocks import storagecounter from coredb import dbfiles @@ -24,12 +26,16 @@ from onionrutils import blockmetadata, bytesconverter You should have received a copy of the GNU General Public License along with this program. If not, see . """ -def set_data(data)->str: + + +def set_data(data) -> str: """Set the data assciated with a hash.""" storage_counter = storagecounter.StorageCounter() data = data dataSize = sys.getsizeof(data) - nonce_hash = crypto.hashers.sha3_hash(bytesconverter.str_to_bytes(blockmetadata.fromdata.get_block_metadata_from_data(data)[2])) + nonce_hash = crypto.hashers.sha3_hash( + bytesconverter.str_to_bytes( + blockmetadata.fromdata.get_block_metadata_from_data(data)[2])) nonce_hash = bytesconverter.bytes_to_str(nonce_hash) if not type(data) is bytes: @@ -39,15 +45,16 @@ def set_data(data)->str: if type(dataHash) is bytes: dataHash = dataHash.decode() - blockFileName = filepaths.block_data_location + dataHash + '.dat' try: onionrstorage.getData(dataHash) except onionrexceptions.NoDataAvailable: - if storage_counter.add_bytes(dataSize) != False: + if storage_counter.add_bytes(dataSize) is not False: onionrstorage.store(data, blockHash=dataHash) conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30) c = conn.cursor() - c.execute("UPDATE hashes SET dataSaved=1 WHERE hash = ?;", (dataHash,)) + c.execute( + "UPDATE hashes SET dataSaved=1 WHERE hash = ?;", + (dataHash,)) conn.commit() conn.close() with open(filepaths.data_nonce_file, 'a') as nonceFile: @@ -55,6 +62,7 @@ def set_data(data)->str: else: raise onionrexceptions.DiskAllocationReached else: - raise onionrexceptions.DataExists("Data is already set for " + dataHash) + raise onionrexceptions.DataExists( + "Data is already set for " + dataHash) return dataHash