1
- from __future__ import unicode_literals
2
1
import binascii
3
2
from datetime import datetime
4
3
from decimal import Decimal
5
4
import ipaddress
6
5
import json
7
6
import logging
8
7
import requests
9
- import six
10
8
11
9
from ... import address
12
10
from ... import exceptions
@@ -134,7 +132,7 @@ def send_transaction(self, blob, relay=True):
134
132
res = self .raw_request (
135
133
"/sendrawtransaction" ,
136
134
{
137
- "tx_as_hex" : six . ensure_text ( binascii .hexlify (blob )),
135
+ "tx_as_hex" : binascii .hexlify (blob ). decode ( ),
138
136
"do_not_relay" : not relay ,
139
137
},
140
138
)
@@ -388,14 +386,11 @@ def submit_block(self, blobs):
388
386
}
389
387
"""
390
388
391
- if isinstance (blobs , (six . binary_type ,) + six . string_types ):
389
+ if isinstance (blobs , (bytes , str ) ):
392
390
blobs = [blobs ]
393
391
394
392
blobs = [
395
- binascii .hexlify (b ).decode ()
396
- if isinstance (b , six .binary_type )
397
- else six .ensure_text (b )
398
- for b in blobs
393
+ binascii .hexlify (b ).decode () if isinstance (b , bytes ) else b for b in blobs
399
394
]
400
395
401
396
return self .raw_jsonrpc_request ("submit_block" , params = blobs )
@@ -707,9 +702,7 @@ def set_bans(self, ip, ban, seconds=None):
707
702
}
708
703
"""
709
704
710
- if isinstance (
711
- ip , six .string_types + six .integer_types
712
- ): # If single element paramters
705
+ if isinstance (ip , (str , int )): # If single element paramters
713
706
user_bans = [{"ip" : ip , "ban" : ban , "seconds" : seconds }]
714
707
else : # If params are iterables, contrust the list of ban entries
715
708
if not (len (ip ) == len (ban ) == len (seconds )):
@@ -736,7 +729,7 @@ def set_bans(self, ip, ban, seconds=None):
736
729
raise ValueError ('"seconds" can not be less than zero' )
737
730
738
731
ban = {}
739
- if isinstance (curr_ip , six . integer_types ):
732
+ if isinstance (curr_ip , int ):
740
733
ban ["ip" ] = curr_ip
741
734
else :
742
735
ban ["host" ] = curr_ip
@@ -823,7 +816,7 @@ def get_output_histogram(
823
816
"""
824
817
825
818
# Coerce amounts paramter
826
- if isinstance (amounts , (Decimal ,) + six . integer_types ):
819
+ if isinstance (amounts , (Decimal , int ) ):
827
820
amounts = [to_atomic (amounts ) if isinstance (amounts , Decimal ) else amounts ]
828
821
elif amounts is None :
829
822
raise ValueError ("amounts is None" )
@@ -893,7 +886,7 @@ def get_fee_estimate(self, grace_blocks=None):
893
886
}
894
887
"""
895
888
896
- if not isinstance (grace_blocks , (type (None ),) + six . integer_types ):
889
+ if not isinstance (grace_blocks , (type (None ), int ) ):
897
890
raise TypeError ("grace_blocks is not an int" )
898
891
elif grace_blocks is not None and grace_blocks < 0 :
899
892
raise ValueError ("grace_blocks < 0" )
@@ -1106,9 +1099,6 @@ def send_raw_transaction(self, tx_as_hex, do_not_relay=False):
1106
1099
"untrusted": bool; True for bootstrap mode, False for full sync mode.
1107
1100
}
1108
1101
"""
1109
-
1110
- tx_as_hex = six .ensure_text (tx_as_hex )
1111
-
1112
1102
return self .raw_request (
1113
1103
"/send_raw_transaction" ,
1114
1104
data = {"tx_as_hex" : tx_as_hex , "do_not_relay" : do_not_relay },
@@ -1287,7 +1277,7 @@ def set_log_categories(self, categories=None):
1287
1277
1288
1278
if not categories :
1289
1279
return self .raw_request ("/set_log_categories" )
1290
- elif isinstance (categories , six . string_types ):
1280
+ elif isinstance (categories , str ):
1291
1281
categories = categories .split ("," )
1292
1282
1293
1283
# Validate categories
@@ -1489,12 +1479,10 @@ def get_outs(self, amount, index, get_txid=True):
1489
1479
}
1490
1480
"""
1491
1481
1492
- if isinstance (index , six . integer_types ): # single element
1482
+ if isinstance (index , int ): # single element
1493
1483
outputs = [
1494
1484
{
1495
- "amount" : amount
1496
- if isinstance (amount , six .integer_types )
1497
- else to_atomic (amount ),
1485
+ "amount" : amount ,
1498
1486
"index" : index ,
1499
1487
}
1500
1488
]
@@ -1506,9 +1494,7 @@ def get_outs(self, amount, index, get_txid=True):
1506
1494
for a , i in zip (amount , index ):
1507
1495
outputs .append (
1508
1496
{
1509
- "amount" : a
1510
- if isinstance (a , six .integer_types )
1511
- else to_atomic (a ),
1497
+ "amount" : a if isinstance (a , int ) else to_atomic (a ),
1512
1498
"index" : i ,
1513
1499
}
1514
1500
)
@@ -1537,10 +1523,6 @@ def update(self, command, path=None):
1537
1523
"status": str; General RPC error code. "OK" means everything looks good.
1538
1524
}
1539
1525
"""
1540
-
1541
- command = six .ensure_text (command )
1542
- path = six .ensure_text (path ) if path is not None else None
1543
-
1544
1526
if command not in ("check" , "download" ):
1545
1527
raise ValueError ('unrecognized command: "{}"' .format (command ))
1546
1528
@@ -1620,10 +1602,12 @@ def _validate_hashlist(self, hashes):
1620
1602
if not hashes :
1621
1603
return []
1622
1604
else :
1623
- if isinstance (hashes , six . string_types ):
1605
+ if isinstance (hashes , str ):
1624
1606
hashes = [hashes ]
1625
1607
else :
1626
- coerce_compatible_str = lambda s : six .ensure_text (str (s ))
1608
+ coerce_compatible_str = (
1609
+ lambda s : s .decode () if isinstance (s , bytes ) else s
1610
+ )
1627
1611
hashes = list (map (coerce_compatible_str , hashes ))
1628
1612
1629
1613
not_valid = lambda h : not self ._is_valid_256_hex (h )
0 commit comments