Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from Cargill/rbuysse-pylint-2.6.0-fixes
Browse files Browse the repository at this point in the history
pylint 2.6.0 fixes
  • Loading branch information
rbuysse authored Aug 31, 2020
2 parents cae5587 + 06114ab commit 4de046e
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
import time
import cbor

from sawtooth_intkey.processor.handler import make_intkey_address

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory

from sawtooth_sdk.protobuf import batch_pb2
from sawtooth_sdk.protobuf import transaction_pb2

from sawtooth_intkey.processor.handler import make_intkey_address


LOGGER = logging.getLogger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions examples/intkey_python/sawtooth_intkey/client_cli/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

import cbor

from sawtooth_intkey.processor.handler import make_intkey_address

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory

from sawtooth_sdk.protobuf import transaction_pb2
from sawtooth_sdk.protobuf import batch_pb2

from sawtooth_intkey.processor.handler import make_intkey_address


LOGGER = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import yaml
import cbor

from sawtooth_intkey.client_cli.exceptions import IntkeyClientException

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory
from sawtooth_signing import ParseError
Expand All @@ -32,8 +34,6 @@
from sawtooth_sdk.protobuf.batch_pb2 import BatchHeader
from sawtooth_sdk.protobuf.batch_pb2 import Batch

from sawtooth_intkey.client_cli.exceptions import IntkeyClientException


def _sha512(data):
return hashlib.sha512(data).hexdigest()
Expand All @@ -50,13 +50,13 @@ def __init__(self, url, keyfile=None):
fd.close()
except OSError as err:
raise IntkeyClientException(
'Failed to read private key: {}'.format(str(err)))
'Failed to read private key: {}'.format(str(err))) from err

try:
private_key = Secp256k1PrivateKey.from_hex(private_key_str)
except ParseError as e:
raise IntkeyClientException(
'Unable to load private key: {}'.format(str(e)))
'Unable to load private key: {}'.format(str(e))) from e

self._signer = CryptoFactory(
create_context('secp256k1')).new_signer(private_key)
Expand Down Expand Up @@ -105,7 +105,7 @@ def _get_status(self, batch_id, wait):
'batch_statuses?id={}&wait={}'.format(batch_id, wait),)
return yaml.safe_load(result)['data'][0]['status']
except BaseException as err:
raise IntkeyClientException(err)
raise IntkeyClientException(err) from err

def _get_prefix(self):
return _sha512('intkey'.encode('utf-8'))[0:6]
Expand Down Expand Up @@ -141,10 +141,10 @@ def _send_request(self, suffix, data=None, content_type=None, name=None):

except requests.ConnectionError as err:
raise IntkeyClientException(
'Failed to connect to REST API: {}'.format(err))
'Failed to connect to REST API: {}'.format(err)) from err

except BaseException as err:
raise IntkeyClientException(err)
raise IntkeyClientException(err) from err

return result.text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@
from base64 import b64encode

import requests
from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory
from sawtooth_signing import ParseError
from sawtooth_signing.secp256k1 import Secp256k1PrivateKey

from sawtooth_intkey.client_cli.workload.workload_generator import \
WorkloadGenerator
from sawtooth_intkey.client_cli.workload.sawtooth_workload import Workload
from sawtooth_intkey.client_cli.create_batch import create_intkey_transaction
from sawtooth_intkey.client_cli.create_batch import create_batch
from sawtooth_intkey.client_cli.exceptions import IntKeyCliException

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory
from sawtooth_signing import ParseError
from sawtooth_signing.secp256k1 import Secp256k1PrivateKey
from sawtooth_sdk.protobuf import batch_pb2

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -85,7 +87,7 @@ class IntKeyWorkload(Workload):
"""

def __init__(self, delegate, args):
super(IntKeyWorkload, self).__init__(delegate, args)
super().__init__(delegate, args)
self._auth_info = args.auth_info
self._urls = []
self._pending_batches = {}
Expand All @@ -103,9 +105,9 @@ def __init__(self, delegate, args):
self._signer = crypto_factory.new_signer(
private_key=private_key)
except ParseError as pe:
raise IntKeyCliException(str(pe))
raise IntKeyCliException(str(pe)) from pe
except IOError as ioe:
raise IntKeyCliException(str(ioe))
raise IntKeyCliException(str(ioe)) from ioe
else:
self._signer = crypto_factory.new_signer(
context.new_random_private_key())
Expand Down
4 changes: 2 additions & 2 deletions examples/intkey_python/sawtooth_intkey/client_cli/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

import cbor

from sawtooth_intkey.processor.handler import make_intkey_address

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory

from sawtooth_sdk.protobuf import batch_pb2
from sawtooth_sdk.protobuf import transaction_pb2

from sawtooth_intkey.processor.handler import make_intkey_address


LOGGER = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

import cbor

from sawtooth_processor_test.message_factory import MessageFactory
from sawtooth_intkey.processor.handler import INTKEY_ADDRESS_PREFIX
from sawtooth_intkey.processor.handler import make_intkey_address

from sawtooth_processor_test.message_factory import MessageFactory


class IntkeyMessageFactory:
def __init__(self, signer=None):
Expand Down
16 changes: 8 additions & 8 deletions examples/intkey_python/sawtooth_intkey/processor/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,23 @@ def _unpack_transaction(transaction):
def _decode_transaction(transaction):
try:
content = cbor.loads(transaction.payload)
except:
raise InvalidTransaction('Invalid payload serialization')
except Exception as e:
raise InvalidTransaction('Invalid payload serialization') from e

try:
verb = content['Verb']
except AttributeError:
raise InvalidTransaction('Verb is required')
raise InvalidTransaction('Verb is required') from AttributeError

try:
name = content['Name']
except AttributeError:
raise InvalidTransaction('Name is required')
raise InvalidTransaction('Name is required') from AttributeError

try:
value = content['Value']
except AttributeError:
raise InvalidTransaction('Value is required')
raise InvalidTransaction('Value is required') from AttributeError

return verb, name, value

Expand Down Expand Up @@ -134,8 +134,8 @@ def _get_state_data(name, context):
return cbor.loads(state_entries[0].data)
except IndexError:
return {}
except:
raise InternalError('Failed to load state data')
except Exception as e:
raise InternalError('Failed to load state data') from e


def _set_state_data(name, state, context):
Expand All @@ -160,7 +160,7 @@ def _do_intkey(verb, name, value, state):
return verbs[verb](name, value, state)
except KeyError:
# This would be a programming error.
raise InternalError('Unhandled verb: {}'.format(verb))
raise InternalError('Unhandled verb: {}'.format(verb)) from KeyError


def _do_set(name, value, state):
Expand Down
3 changes: 2 additions & 1 deletion examples/intkey_python/sawtooth_intkey/processor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import argparse
import pkg_resources

from sawtooth_intkey.processor.handler import IntkeyTransactionHandler

from sawtooth_sdk.processor.core import TransactionProcessor
from sawtooth_sdk.processor.log import init_console_logging
from sawtooth_sdk.processor.log import log_configuration
from sawtooth_sdk.processor.config import get_log_config
from sawtooth_sdk.processor.config import get_log_dir
from sawtooth_intkey.processor.handler import IntkeyTransactionHandler


DISTRIBUTION_NAME = 'sawtooth-intkey'
Expand Down
2 changes: 1 addition & 1 deletion examples/intkey_python/tests/test_tp_intkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import cbor

from sawtooth_intkey.intkey_message_factory import IntkeyMessageFactory
from sawtooth_processor_test.transaction_processor_test_case \
import TransactionProcessorTestCase
from sawtooth_intkey.intkey_message_factory import IntkeyMessageFactory
from sawtooth_sdk.protobuf.validator_pb2 import Message


Expand Down
2 changes: 1 addition & 1 deletion examples/xo_python/sawtooth_xo/processor/config/xo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def load_toml_xo_config(filename):
except IOError as e:
raise LocalConfigurationError(
"Unable to load transaction processor configuration file:"
" {}".format(str(e)))
" {}".format(str(e))) from e

toml_config = toml.loads(raw_config)
invalid_keys = set(toml_config.keys()).difference(
Expand Down
9 changes: 4 additions & 5 deletions examples/xo_python/sawtooth_xo/processor/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@

import logging


from sawtooth_sdk.processor.handler import TransactionHandler
from sawtooth_sdk.processor.exceptions import InvalidTransaction
from sawtooth_sdk.processor.exceptions import InternalError

from sawtooth_xo.processor.xo_payload import XoPayload
from sawtooth_xo.processor.xo_state import Game
from sawtooth_xo.processor.xo_state import XoState
from sawtooth_xo.processor.xo_state import XO_NAMESPACE

from sawtooth_sdk.processor.handler import TransactionHandler
from sawtooth_sdk.processor.exceptions import InvalidTransaction
from sawtooth_sdk.processor.exceptions import InternalError


LOGGER = logging.getLogger(__name__)

Expand Down
13 changes: 7 additions & 6 deletions examples/xo_python/sawtooth_xo/processor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
import argparse
import pkg_resources

from sawtooth_sdk.processor.core import TransactionProcessor
from sawtooth_sdk.processor.log import init_console_logging
from sawtooth_sdk.processor.log import log_configuration
from sawtooth_sdk.processor.config import get_log_config
from sawtooth_sdk.processor.config import get_log_dir
from sawtooth_sdk.processor.config import get_config_dir
from sawtooth_xo.processor.handler import XoTransactionHandler
from sawtooth_xo.processor.config.xo import XOConfig
from sawtooth_xo.processor.config.xo import \
Expand All @@ -33,6 +27,13 @@
from sawtooth_xo.processor.config.xo import \
merge_xo_config

from sawtooth_sdk.processor.core import TransactionProcessor
from sawtooth_sdk.processor.log import init_console_logging
from sawtooth_sdk.processor.log import log_configuration
from sawtooth_sdk.processor.config import get_log_config
from sawtooth_sdk.processor.config import get_log_dir
from sawtooth_sdk.processor.config import get_config_dir


DISTRIBUTION_NAME = 'sawtooth-xo'

Expand Down
6 changes: 3 additions & 3 deletions examples/xo_python/sawtooth_xo/processor/xo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, payload):
try:
# The payload is csv utf-8 encoded string
name, action, space = payload.decode().split(",")
except ValueError:
raise InvalidTransaction("Invalid payload serialization")
except ValueError as e:
raise InvalidTransaction("Invalid payload serialization") from e

if not name:
raise InvalidTransaction('Name is required')
Expand All @@ -45,7 +45,7 @@ def __init__(self, payload):
"Space must be an integer from 1 to 9")
except ValueError:
raise InvalidTransaction(
'Space must be an integer from 1 to 9')
'Space must be an integer from 1 to 9') from ValueError

if action == 'take':
space = int(space)
Expand Down
4 changes: 2 additions & 2 deletions examples/xo_python/sawtooth_xo/processor/xo_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def _deserialize(self, data):
name, board, state, player1, player2 = game.split(",")

games[name] = Game(name, board, state, player1, player2)
except ValueError:
raise InternalError("Failed to deserialize game data")
except ValueError as e:
raise InternalError("Failed to deserialize game data") from e

return games

Expand Down
14 changes: 7 additions & 7 deletions examples/xo_python/sawtooth_xo/xo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import requests
import yaml

from sawtooth_xo.xo_exceptions import XoException

from sawtooth_signing import create_context
from sawtooth_signing import CryptoFactory
from sawtooth_signing import ParseError
Expand All @@ -32,8 +34,6 @@
from sawtooth_sdk.protobuf.batch_pb2 import BatchHeader
from sawtooth_sdk.protobuf.batch_pb2 import Batch

from sawtooth_xo.xo_exceptions import XoException


def _sha512(data):
return hashlib.sha512(data).hexdigest()
Expand All @@ -54,13 +54,13 @@ def __init__(self, base_url, keyfile=None):
except OSError as err:
raise XoException(
'Failed to read private key {}: {}'.format(
keyfile, str(err)))
keyfile, str(err))) from err

try:
private_key = Secp256k1PrivateKey.from_hex(private_key_str)
except ParseError as e:
raise XoException(
'Unable to load private key: {}'.format(str(e)))
'Unable to load private key: {}'.format(str(e))) from e

self._signer = CryptoFactory(create_context('secp256k1')) \
.new_signer(private_key)
Expand Down Expand Up @@ -130,7 +130,7 @@ def _get_status(self, batch_id, wait, auth_user=None, auth_password=None):
auth_password=auth_password)
return yaml.safe_load(result)['data'][0]['status']
except BaseException as err:
raise XoException(err)
raise XoException(err) from err

def _get_prefix(self):
return _sha512('xo'.encode('utf-8'))[0:6]
Expand Down Expand Up @@ -177,10 +177,10 @@ def _send_request(self,

except requests.ConnectionError as err:
raise XoException(
'Failed to connect to {}: {}'.format(url, str(err)))
'Failed to connect to {}: {}'.format(url, str(err))) from err

except BaseException as err:
raise XoException(err)
raise XoException(err) from err

return result.text

Expand Down
2 changes: 1 addition & 1 deletion examples/xo_python/tests/test_tp_xo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import logging

from sawtooth_xo.xo_message_factory import XoMessageFactory
from sawtooth_processor_test.transaction_processor_test_case \
import TransactionProcessorTestCase
from sawtooth_xo.xo_message_factory import XoMessageFactory


LOGGER = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 4de046e

Please sign in to comment.