Skip to content

Commit b0f545c

Browse files
committed
Prefix bord/bchr with _
Keeps them from being exported in module namespaces.
1 parent d01e53f commit b0f545c

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
@@ -15,12 +15,12 @@
1515
from __future__ import absolute_import, division, print_function, unicode_literals
1616

1717
import sys
18-
bchr = chr
19-
bord = ord
18+
_bchr = chr
19+
_bord = ord
2020
if sys.version > '3':
2121
long = int
22-
bchr = lambda x: bytes([x])
23-
bord = lambda x: x
22+
_bchr = lambda x: bytes([x])
23+
_bord = lambda x: x
2424

2525
import binascii
2626

@@ -108,7 +108,7 @@ def __new__(cls, s):
108108
if check0 != check1:
109109
raise Base58ChecksumError('Checksum mismatch: expected %r, calculated %r' % (check0, check1))
110110

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

113113
def __init__(self, s):
114114
"""Initialize from base58-encoded string
@@ -138,7 +138,7 @@ def to_bytes(self):
138138

139139
def __str__(self):
140140
"""Convert to string"""
141-
vs = bchr(self.nVersion) + self
141+
vs = _bchr(self.nVersion) + self
142142
check = bitcoin.core.Hash(vs)[0:4]
143143
return encode(vs + check)
144144

bitcoin/core/script.py

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

2020
import sys
21-
bchr = chr
22-
bord = ord
21+
_bchr = chr
22+
_bord = ord
2323
if sys.version > '3':
2424
long = int
25-
bchr = lambda x: bytes([x])
26-
bord = lambda x: x
25+
_bchr = lambda x: bytes([x])
26+
_bord = lambda x: x
2727

2828
import copy
2929
import struct
@@ -46,9 +46,9 @@ class CScriptOp(int):
4646
def encode_op_pushdata(d):
4747
"""Encode a PUSHDATA op, returning bytes"""
4848
if len(d) < 0x4c:
49-
return b'' + bchr(len(d)) + d # OP_PUSHDATA
49+
return b'' + _bchr(len(d)) + d # OP_PUSHDATA
5050
elif len(d) <= 0xff:
51-
return b'\x4c' + bchr(len(d)) + d # OP_PUSHDATA1
51+
return b'\x4c' + _bchr(len(d)) + d # OP_PUSHDATA1
5252
elif len(d) <= 0xffff:
5353
return b'\x4d' + struct.pack(b'<H', len(d)) + d # OP_PUSHDATA2
5454
elif len(d) <= 0xffffffff:
@@ -514,12 +514,12 @@ class CScript(bytes):
514514
def __coerce_instance(cls, other):
515515
# Coerce other into bytes
516516
if isinstance(other, CScriptOp):
517-
other = bchr(other)
517+
other = _bchr(other)
518518
elif isinstance(other, (int, long)):
519519
if 0 <= other <= 16:
520-
other = bytes(bchr(CScriptOp.encode_op_n(other)))
520+
other = bytes(_bchr(CScriptOp.encode_op_n(other)))
521521
elif other == -1:
522-
other = bytes(bchr(OP_1NEGATE))
522+
other = bytes(_bchr(OP_1NEGATE))
523523
else:
524524
other = CScriptOp.encode_op_pushdata(bitcoin.core.bignum.bn2vch(other))
525525
elif isinstance(other, (bytes, bytearray)):
@@ -562,7 +562,7 @@ def raw_iter(self):
562562
i = 0
563563
while i < len(self):
564564
sop_idx = i
565-
opcode = bord(self[i])
565+
opcode = _bord(self[i])
566566
i += 1
567567

568568
if opcode > OP_PUSHDATA4:
@@ -578,21 +578,21 @@ def raw_iter(self):
578578
pushdata_type = 'PUSHDATA1'
579579
if i >= len(self):
580580
raise CScriptInvalidError('PUSHDATA1: missing data length')
581-
datasize = bord(self[i])
581+
datasize = _bord(self[i])
582582
i += 1
583583

584584
elif opcode == OP_PUSHDATA2:
585585
pushdata_type = 'PUSHDATA2'
586586
if i + 1 >= len(self):
587587
raise CScriptInvalidError('PUSHDATA2: missing data length')
588-
datasize = bord(self[i]) + (bord(self[i+1]) << 8)
588+
datasize = _bord(self[i]) + (_bord(self[i+1]) << 8)
589589
i += 2
590590

591591
elif opcode == OP_PUSHDATA4:
592592
pushdata_type = 'PUSHDATA4'
593593
if i + 3 >= len(self):
594594
raise CScriptInvalidError('PUSHDATA4: missing data length')
595-
datasize = bord(self[i]) + (bord(self[i+1]) << 8) + (bord(self[i+2]) << 16) + (bord(self[i+3]) << 24)
595+
datasize = _bord(self[i]) + (_bord(self[i+1]) << 8) + (_bord(self[i+2]) << 16) + (_bord(self[i+3]) << 24)
596596
i += 4
597597

598598
else:
@@ -664,9 +664,9 @@ def is_p2sh(self):
664664
Note that this test is consensus-critical.
665665
"""
666666
return (len(self) == 23 and
667-
bord(self[0]) == OP_HASH160 and
668-
bord(self[1]) == 0x14 and
669-
bord(self[22]) == OP_EQUAL)
667+
_bord(self[0]) == OP_HASH160 and
668+
_bord(self[1]) == 0x14 and
669+
_bord(self[22]) == OP_EQUAL)
670670

671671
def is_push_only(self):
672672
"""Test if the script only contains pushdata ops
@@ -696,7 +696,7 @@ def has_canonical_pushes(self):
696696
if op > OP_16:
697697
continue
698698

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

@@ -719,7 +719,7 @@ def has_canonical_pushes(self):
719719
def is_unspendable(self):
720720
"""Test if the script is provably unspendable"""
721721
return (len(self) > 0 and
722-
bord(self[0]) == OP_RETURN)
722+
_bord(self[0]) == OP_RETURN)
723723

724724
def is_valid(self):
725725
"""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
@@ -19,10 +19,10 @@
1919
from __future__ import absolute_import, division, print_function, unicode_literals
2020

2121
import sys
22-
bord = ord
22+
_bord = ord
2323
if sys.version > '3':
2424
long = int
25-
bord = lambda x: x
25+
_bord = lambda x: x
2626

2727
import copy
2828
import hashlib
@@ -103,7 +103,7 @@ def _CastToBigNum(s, err_raiser):
103103

104104
def _CastToBool(s):
105105
for i in range(len(s)):
106-
sv = bord(s[i])
106+
sv = _bord(s[i])
107107
if sv != 0:
108108
if (i == (len(s) - 1)) and (sv == 0x80):
109109
return False
@@ -118,7 +118,7 @@ def _CheckSig(sig, pubkey, script, txTo, inIdx, err_raiser):
118118

119119
if len(sig) == 0:
120120
return False
121-
hashtype = bord(sig[-1])
121+
hashtype = _bord(sig[-1])
122122
sig = sig[:-1]
123123

124124
# 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
@@ -23,12 +23,12 @@
2323
import sys
2424

2525
if sys.version > '3':
26-
bchr = lambda x: bytes([x])
27-
bord = lambda x: x[0]
26+
_bchr = lambda x: bytes([x])
27+
_bord = lambda x: x[0]
2828
from io import BytesIO
2929
else:
30-
bchr = chr
31-
bord = ord
30+
_bchr = chr
31+
_bord = ord
3232
from cStringIO import StringIO as BytesIO
3333

3434
MAX_SIZE = 0x02000000
@@ -194,20 +194,20 @@ def stream_serialize(cls, i, f):
194194
if i < 0:
195195
raise ValueError('varint must be non-negative integer')
196196
elif i < 0xfd:
197-
f.write(bchr(i))
197+
f.write(_bchr(i))
198198
elif i <= 0xffff:
199-
f.write(bchr(0xfd))
199+
f.write(_bchr(0xfd))
200200
f.write(struct.pack(b'<H', i))
201201
elif i <= 0xffffffff:
202-
f.write(bchr(0xfe))
202+
f.write(_bchr(0xfe))
203203
f.write(struct.pack(b'<I', i))
204204
else:
205-
f.write(bchr(0xff))
205+
f.write(_bchr(0xff))
206206
f.write(struct.pack(b'<Q', i))
207207

208208
@classmethod
209209
def stream_deserialize(cls, f):
210-
r = bord(ser_read(f, 1))
210+
r = _bord(ser_read(f, 1))
211211
if r < 0xfd:
212212
return r
213213
elif r == 0xfd:

bitcoin/wallet.py

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

2020
import sys
21-
bchr = chr
22-
bord = ord
21+
_bord = ord
2322
if sys.version > '3':
24-
bchr = lambda x: bytes([x])
25-
bord = lambda x: x
23+
_bord = lambda x: x
2624

2725
import bitcoin
2826
import bitcoin.base58
@@ -166,11 +164,11 @@ def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, acc
166164
raise CBitcoinAddressError('not a P2PKH scriptPubKey: script is invalid')
167165

168166
if (len(scriptPubKey) == 25
169-
and bord(scriptPubKey[0]) == script.OP_DUP
170-
and bord(scriptPubKey[1]) == script.OP_HASH160
171-
and bord(scriptPubKey[2]) == 0x14
172-
and bord(scriptPubKey[23]) == script.OP_EQUALVERIFY
173-
and bord(scriptPubKey[24]) == script.OP_CHECKSIG):
167+
and _bord(scriptPubKey[0]) == script.OP_DUP
168+
and _bord(scriptPubKey[1]) == script.OP_HASH160
169+
and _bord(scriptPubKey[2]) == 0x14
170+
and _bord(scriptPubKey[23]) == script.OP_EQUALVERIFY
171+
and _bord(scriptPubKey[24]) == script.OP_CHECKSIG):
174172
return cls.from_bytes(scriptPubKey[3:23], bitcoin.params.BASE58_PREFIXES['PUBKEY_ADDR'])
175173

176174
elif accept_bare_checksig:
@@ -179,14 +177,14 @@ def from_scriptPubKey(cls, scriptPubKey, accept_non_canonical_pushdata=True, acc
179177
# We can operate on the raw bytes directly because we've
180178
# canonicalized everything above.
181179
if (len(scriptPubKey) == 35 # compressed
182-
and bord(scriptPubKey[0]) == 0x21
183-
and bord(scriptPubKey[34]) == script.OP_CHECKSIG):
180+
and _bord(scriptPubKey[0]) == 0x21
181+
and _bord(scriptPubKey[34]) == script.OP_CHECKSIG):
184182

185183
pubkey = scriptPubKey[1:34]
186184

187185
elif (len(scriptPubKey) == 67 # uncompressed
188-
and bord(scriptPubKey[0]) == 0x41
189-
and bord(scriptPubKey[66]) == script.OP_CHECKSIG):
186+
and _bord(scriptPubKey[0]) == 0x41
187+
and _bord(scriptPubKey[66]) == script.OP_CHECKSIG):
190188

191189
pubkey = scriptPubKey[1:65]
192190

@@ -243,4 +241,4 @@ def __init__(self, s):
243241
raise CBitcoinSecretError('Not a base58-encoded secret key: got nVersion=%d; expected nVersion=%d' % \
244242
(self.nVersion, bitcoin.params.BASE58_PREFIXES['SECRET_KEY']))
245243

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

0 commit comments

Comments
 (0)