Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 6690191

Browse files
committed
cleanup checking
1 parent 7b6db63 commit 6690191

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

ethereum/abi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ethereum import utils
1010
from ethereum.utils import encode_int, zpad, big_endian_to_int, is_numeric, is_string, ceil32
11-
from ethereum.utils import isnumeric, TT256, TT255
11+
from ethereum.utils import TT256, TT255
1212

1313

1414
def json_decode(data):
@@ -327,7 +327,7 @@ def encode_single(typ, arg):
327327
elif base == 'hash':
328328
if not (int(sub) and int(sub) <= 32):
329329
raise EncodingError("too long: %r" % arg)
330-
if isnumeric(arg):
330+
if is_numeric(arg):
331331
return zpad(encode_int(arg), 32)
332332
elif len(arg) == int(sub):
333333
return zpad(arg, 32)
@@ -338,7 +338,7 @@ def encode_single(typ, arg):
338338
# Addresses: address (== hash160)
339339
elif base == 'address':
340340
assert sub == ''
341-
if isnumeric(arg):
341+
if is_numeric(arg):
342342
return zpad(encode_int(arg), 32)
343343
elif len(arg) == 20:
344344
return zpad(arg, 32)

ethereum/ethpow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def mine(self, rounds=1000, start_nonce=0):
107107

108108

109109
def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):
110-
assert utils.isnumeric(start_nonce)
110+
assert utils.is_numeric(start_nonce)
111111
cache = get_cache(block_number)
112112
nonce = start_nonce
113113
target = utils.zpad(utils.int_to_big_endian(2**256 // (difficulty or 1)), 32)

ethereum/slogging.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import sys
12
import logging
23
import json
34
import textwrap
45
from json.encoder import JSONEncoder
56
from logging import StreamHandler, Formatter, FileHandler
6-
from ethereum.utils import bcolors, isnumeric
77

88

99
DEFAULT_LOGLEVEL = 'INFO'
@@ -20,6 +20,33 @@
2020
log_listeners = []
2121

2222

23+
if sys.version_info.major == 2:
24+
integer_types = (int, long)
25+
number_types = (int, long, float, complex)
26+
else:
27+
integer_types = (int,)
28+
number_types = (int, float, complex)
29+
30+
31+
def is_integer(value):
32+
return isinstance(value, integer_types)
33+
34+
35+
def is_number(value):
36+
return isinstance(value, number_types)
37+
38+
39+
class bcolors:
40+
HEADER = '\033[95m'
41+
OKBLUE = '\033[94m'
42+
OKGREEN = '\033[92m'
43+
WARNING = '\033[91m'
44+
FAIL = '\033[91m'
45+
ENDC = '\033[0m'
46+
BOLD = '\033[1m'
47+
UNDERLINE = '\033[4m'
48+
49+
2350
def _inject_into_logger(name, code, namespace=None):
2451
# This is a hack to fool the logging module into reporting correct source files.
2552
# It determines the actual source of a logging call by inspecting the stack frame's
@@ -190,7 +217,7 @@ def format_message(self, msg, kwargs, highlight, level):
190217
msg = json.dumps(message, cls=_LogJSONEncoder)
191218
except UnicodeDecodeError:
192219
message.update({
193-
k: v if isnumeric(v) or isinstance(v, (float, complex)) else repr(v)
220+
k: v if is_number(v) else repr(v)
194221
for k, v in kwargs.items()
195222
})
196223
msg = json.dumps(message, cls=_LogJSONEncoder)
@@ -260,7 +287,7 @@ def _stringify_dict_keys(input_):
260287
res = {}
261288
for k, v in input_.items():
262289
v = _stringify_dict_keys(v)
263-
if not isinstance(k, (int, long, bool, None.__class__)):
290+
if not is_integer(k) and not isinstance(k, (bool, None.__class__)):
264291
k = str(k)
265292
res[k] = v
266293
elif isinstance(input_, (list, tuple)):

ethereum/utils.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def to_string_for_regexp(value):
6262
def bytearray_to_bytestr(value):
6363
return bytes(value)
6464

65-
isnumeric = is_numeric
66-
6765

6866
def mk_contract_address(sender, nonce):
6967
return sha3(rlp.encode([normalize_address(sender), nonce]))[12:]
@@ -145,7 +143,7 @@ def check_and_strip_checksum(x):
145143

146144

147145
def normalize_address(x, allow_blank=False):
148-
if isinstance(x, (int, long)):
146+
if is_numeric(x):
149147
return int_to_addr(x)
150148
if allow_blank and (x == '' or x == b''):
151149
return b''
@@ -428,17 +426,6 @@ def __init__(self):
428426
trie_root = Binary.fixed_length(32, allow_empty=True)
429427

430428

431-
class bcolors:
432-
HEADER = '\033[95m'
433-
OKBLUE = '\033[94m'
434-
OKGREEN = '\033[92m'
435-
WARNING = '\033[91m'
436-
FAIL = '\033[91m'
437-
ENDC = '\033[0m'
438-
BOLD = '\033[1m'
439-
UNDERLINE = '\033[4m'
440-
441-
442429
def DEBUG(msg, *args, **kwargs):
443430
from ethereum import slogging
444431

0 commit comments

Comments
 (0)