Skip to content

Commit c107b9e

Browse files
committed
Prefix bord/bchr with _
Keeps them from being exported in module namespaces. [ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:21 2015 ]
1 parent d2651c9 commit c107b9e

File tree

5 files changed

+49
-51
lines changed

5 files changed

+49
-51
lines changed

bitcoin/base58.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
from __future__ import absolute_import, division, print_function, unicode_literals
1515

1616
import sys
17-
bchr = chr
18-
bord = ord
17+
_bchr = chr
18+
_bord = ord
1919
if sys.version > '3':
2020
long = int
21-
bchr = lambda x: bytes([x])
22-
bord = lambda x: x
21+
_bchr = lambda x: bytes([x])
22+
_bord = lambda x: x
2323

2424
import binascii
2525

@@ -116,7 +116,7 @@ def __new__(cls, s):
116116
'Checksum mismatch: expected %r, calculated %r' %
117117
(check0, check1))
118118

119-
return cls.from_bytes(data, bord(verbyte[0]))
119+
return cls.from_bytes(data, _bord(verbyte[0]))
120120

121121
def __init__(self, s):
122122
"""Initialize from base58-encoded string
@@ -148,7 +148,7 @@ def to_bytes(self):
148148

149149
def __str__(self):
150150
"""Convert to string"""
151-
vs = bchr(self.nVersion) + self
151+
vs = _bchr(self.nVersion) + self
152152
check = bitcoin.core.Hash(vs)[0:4]
153153
return encode(vs + check)
154154

bitcoin/core/script.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
from __future__ import absolute_import, division, print_function, unicode_literals
1818

1919
import sys
20-
bchr = chr
21-
bord = ord
20+
_bchr = chr
21+
_bord = ord
2222
if sys.version > '3':
2323
long = int
24-
bchr = lambda x: bytes([x])
25-
bord = lambda x: x
24+
_bchr = lambda x: bytes([x])
25+
_bord = lambda x: x
2626

2727
import copy
2828
import struct
@@ -47,9 +47,9 @@ class CScriptOp(int):
4747
def encode_op_pushdata(d):
4848
"""Encode a PUSHDATA op, returning bytes"""
4949
if len(d) < 0x4c:
50-
return b'' + bchr(len(d)) + d # OP_PUSHDATA
50+
return b'' + _bchr(len(d)) + d # OP_PUSHDATA
5151
elif len(d) <= 0xff:
52-
return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1
52+
return b'\x4c' + _bchr(len(d)) + d # OP_PUSHDATA1
5353
elif len(d) <= 0xffff:
5454
return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
5555
elif len(d) <= 0xffffffff:
@@ -520,12 +520,12 @@ class CScript(bytes):
520520
def __coerce_instance(cls, other):
521521
# Coerce other into bytes
522522
if isinstance(other, CScriptOp):
523-
other = bchr(other)
523+
other = _bchr(other)
524524
elif isinstance(other, (int, long)):
525525
if 0 <= other <= 16:
526-
other = bytes(bchr(CScriptOp.encode_op_n(other)))
526+
other = bytes(_bchr(CScriptOp.encode_op_n(other)))
527527
elif other == -1:
528-
other = bytes(bchr(OP_1NEGATE))
528+
other = bytes(_bchr(OP_1NEGATE))
529529
else:
530530
other = CScriptOp.encode_op_pushdata(bitcoin.core.bignum.bn2vch(
531531
other))
@@ -572,7 +572,7 @@ def raw_iter(self):
572572
i = 0
573573
while i < len(self):
574574
sop_idx = i
575-
opcode = bord(self[i])
575+
opcode = _bord(self[i])
576576
i += 1
577577

578578
if opcode > OP_PUSHDATA4:
@@ -589,24 +589,24 @@ def raw_iter(self):
589589
if i >= len(self):
590590
raise CScriptInvalidError(
591591
'PUSHDATA1: missing data length')
592-
datasize = bord(self[i])
592+
datasize = _bord(self[i])
593593
i += 1
594594

595595
elif opcode == OP_PUSHDATA2:
596596
pushdata_type = 'PUSHDATA2'
597597
if i + 1 >= len(self):
598598
raise CScriptInvalidError(
599599
'PUSHDATA2: missing data length')
600-
datasize = bord(self[i]) + (bord(self[i + 1]) << 8)
600+
datasize = _bord(self[i]) + (_bord(self[i + 1]) << 8)
601601
i += 2
602602

603603
elif opcode == OP_PUSHDATA4:
604604
pushdata_type = 'PUSHDATA4'
605605
if i + 3 >= len(self):
606606
raise CScriptInvalidError(
607607
'PUSHDATA4: missing data length')
608-
datasize = bord(self[i]) + (bord(self[i + 1]) << 8) + (
609-
bord(self[i + 2]) << 16) + (bord(self[i + 3]) << 24)
608+
datasize = _bord(self[i]) + (_bord(self[i + 1]) << 8) + (
609+
_bord(self[i + 2]) << 16) + (_bord(self[i + 3]) << 24)
610610
i += 4
611611

612612
else:
@@ -677,8 +677,8 @@ def is_p2sh(self):
677677
678678
Note that this test is consensus-critical.
679679
"""
680-
return (len(self) == 23 and bord(self[0]) == OP_HASH160 and
681-
bord(self[1]) == 0x14 and bord(self[22]) == OP_EQUAL)
680+
return (len(self) == 23 and _bord(self[0]) == OP_HASH160 and
681+
_bord(self[1]) == 0x14 and _bord(self[22]) == OP_EQUAL)
682682

683683
def is_push_only(self):
684684
"""Test if the script only contains pushdata ops
@@ -709,7 +709,7 @@ def has_canonical_pushes(self):
709709
continue
710710

711711
elif op < OP_PUSHDATA1 and op > OP_0 and len(
712-
data) == 1 and bord(data[0]) <= 16:
712+
data) == 1 and _bord(data[0]) <= 16:
713713
# Could have used an OP_n code, rather than a 1-byte push.
714714
return False
715715

@@ -731,7 +731,7 @@ def has_canonical_pushes(self):
731731

732732
def is_unspendable(self):
733733
"""Test if the script is provably unspendable"""
734-
return (len(self) > 0 and bord(self[0]) == OP_RETURN)
734+
return (len(self) > 0 and _bord(self[0]) == OP_RETURN)
735735

736736
def is_valid(self):
737737
"""Return True if the script is valid, False otherwise

bitcoin/core/scripteval.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
from __future__ import absolute_import, division, print_function, unicode_literals
1919

2020
import sys
21-
bord = ord
21+
_bord = ord
2222
if sys.version > '3':
2323
long = int
24-
bord = lambda x: x
24+
_bord = lambda x: x
2525

2626
import copy
2727
import hashlib
@@ -121,7 +121,7 @@ def _CastToBigNum(s, err_raiser):
121121

122122
def _CastToBool(s):
123123
for i in range(len(s)):
124-
sv = bord(s[i])
124+
sv = _bord(s[i])
125125
if sv != 0:
126126
if (i == (len(s) - 1)) and (sv == 0x80):
127127
return False
@@ -136,7 +136,7 @@ def _CheckSig(sig, pubkey, script, txTo, inIdx, err_raiser):
136136

137137
if len(sig) == 0:
138138
return False
139-
hashtype = bord(sig[-1])
139+
hashtype = _bord(sig[-1])
140140
sig = sig[:-1]
141141

142142
# Raw signature hash due to the SIGHASH_SINGLE bug

bitcoin/core/serialize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import sys
2323

2424
if sys.version > '3':
25-
bchr = lambda x: bytes([x])
26-
bord = lambda x: x[0]
25+
_bchr = lambda x: bytes([x])
26+
_bord = lambda x: x[0]
2727
from io import BytesIO
2828
else:
29-
bchr = chr
30-
bord = ord
29+
_bchr = chr
30+
_bord = ord
3131
from cStringIO import StringIO as BytesIO
3232

3333
MAX_SIZE = 0x02000000
@@ -203,20 +203,20 @@ def stream_serialize(cls, i, f):
203203
if i < 0:
204204
raise ValueError('varint must be non-negative integer')
205205
elif i < 0xfd:
206-
f.write(bchr(i))
206+
f.write(_bchr(i))
207207
elif i <= 0xffff:
208-
f.write(bchr(0xfd))
208+
f.write(_bchr(0xfd))
209209
f.write(struct.pack(b'<H', i))
210210
elif i <= 0xffffffff:
211-
f.write(bchr(0xfe))
211+
f.write(_bchr(0xfe))
212212
f.write(struct.pack(b'<I', i))
213213
else:
214-
f.write(bchr(0xff))
214+
f.write(_bchr(0xff))
215215
f.write(struct.pack(b'<Q', i))
216216

217217
@classmethod
218218
def stream_deserialize(cls, f):
219-
r = bord(ser_read(f, 1))
219+
r = _bord(ser_read(f, 1))
220220
if r < 0xfd:
221221
return r
222222
elif r == 0xfd:

bitcoin/wallet.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
from __future__ import absolute_import, division, print_function, unicode_literals
1818

1919
import sys
20-
bchr = chr
21-
bord = ord
20+
_bord = ord
2221
if sys.version > '3':
23-
bchr = lambda x: bytes([x])
24-
bord = lambda x: x
22+
_bord = lambda x: x
2523

2624
import bitcoin
2725
import bitcoin.base58
@@ -180,11 +178,11 @@ def from_scriptPubKey(cls,
180178
'not a P2PKH scriptPubKey: script is invalid')
181179

182180
if (len(scriptPubKey) == 25 and
183-
bord(scriptPubKey[0]) == script.OP_DUP and
184-
bord(scriptPubKey[1]) == script.OP_HASH160 and
185-
bord(scriptPubKey[2]) == 0x14 and
186-
bord(scriptPubKey[23]) == script.OP_EQUALVERIFY and
187-
bord(scriptPubKey[24]) == script.OP_CHECKSIG):
181+
_bord(scriptPubKey[0]) == script.OP_DUP and
182+
_bord(scriptPubKey[1]) == script.OP_HASH160 and
183+
_bord(scriptPubKey[2]) == 0x14 and
184+
_bord(scriptPubKey[23]) == script.OP_EQUALVERIFY and
185+
_bord(scriptPubKey[24]) == script.OP_CHECKSIG):
188186
return cls.from_bytes(scriptPubKey[3:23],
189187
bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
190188

@@ -194,14 +192,14 @@ def from_scriptPubKey(cls,
194192
# We can operate on the raw bytes directly because we've
195193
# canonicalized everything above.
196194
if (len(scriptPubKey) == 35 # compressed
197-
and bord(scriptPubKey[0]) == 0x21 and
198-
bord(scriptPubKey[34]) == script.OP_CHECKSIG):
195+
and _bord(scriptPubKey[0]) == 0x21 and
196+
_bord(scriptPubKey[34]) == script.OP_CHECKSIG):
199197

200198
pubkey = scriptPubKey[1:34]
201199

202200
elif (len(scriptPubKey) == 67 # uncompressed
203-
and bord(scriptPubKey[0]) == 0x41 and
204-
bord(scriptPubKey[66]) == script.OP_CHECKSIG):
201+
and _bord(scriptPubKey[0]) == 0x41 and
202+
_bord(scriptPubKey[66]) == script.OP_CHECKSIG):
205203

206204
pubkey = scriptPubKey[1:65]
207205

@@ -263,4 +261,4 @@ def __init__(self, s):
263261
raise CBitcoinSecretError('Not a base58-encoded secret key: got nVersion=%d; expected nVersion=%d' % \
264262
(self.nVersion, bitcoin.params.BASE58_PREFIXES['SECRET_KEY']))
265263

266-
CKey.__init__(self, self[0:32], len(self) > 32 and bord(self[32]) == 1)
264+
CKey.__init__(self, self[0:32], len(self) > 32 and _bord(self[32]) == 1)

0 commit comments

Comments
 (0)