Skip to content

Commit c1e7797

Browse files
committed
Add __all__ to all modules
Be explicit about what we're exporting everywhere. [ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:30 2015 ]
1 parent 7ae1d0f commit c1e7797

File tree

11 files changed

+262
-14
lines changed

11 files changed

+262
-14
lines changed

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ accomodate this. In addition see b2x() and b2lx() for conversion from bytes to
6969
big/little-endian hex.
7070

7171

72+
Module import style
73+
-------------------
74+
75+
While not always good style, it's often convenient for quick scripts if import
76+
* can be used. To support that all the modules have __all__ defined
77+
appropriately.
78+
79+
7280
Example Code
7381
------------
7482

bitcoin/base58.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,12 @@ def __str__(self):
154154

155155
def __repr__(self):
156156
return '%s(%r)' % (self.__class__.__name__, str(self))
157+
158+
159+
__all__ = ('B58_DIGITS',
160+
'Base58Error',
161+
'InvalidBase58Error',
162+
'encode',
163+
'decode',
164+
'Base58ChecksumError',
165+
'CBase58Data',)

bitcoin/bloom.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,6 @@ def stream_serialize(self, f):
193193
bitcoin.core.serialize.BytesSerializer.stream_serialize(
194194
bytes(self.vData), f)
195195
f.write(self.__struct.pack(self.nHashFuncs, self.nTweak, self.nFlags))
196+
197+
198+
__all__ = ('MurmurHash3', 'CBloomFilter',)

bitcoin/core/__init__.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# propagated, or distributed except according to the terms contained in the
1010
# LICENSE file.
1111

12-
from __future__ import absolute_import, division, print_function, unicode_literals
12+
from __future__ import absolute_import, division, print_function
1313

1414
import binascii
1515
import hashlib
@@ -805,3 +805,41 @@ def CheckBlock(block, fCheckPoW=True, fCheckMerkleRoot=True, cur_time=None):
805805
# Check merkle root
806806
if fCheckMerkleRoot and block.hashMerkleRoot != block.calc_merkle_root():
807807
raise CheckBlockError("CheckBlock() : hashMerkleRoot mismatch")
808+
809+
810+
__all__ = ('Hash',
811+
'Hash160',
812+
'COIN',
813+
'MAX_MONEY',
814+
'MAX_BLOCK_SIZE',
815+
'MAX_BLOCK_SIGOPS',
816+
'MoneyRange',
817+
'x',
818+
'b2x',
819+
'lx',
820+
'b2lx',
821+
'str_money_value',
822+
'ValidationError',
823+
'COutPoint',
824+
'CMutableOutPoint',
825+
'CTxIn',
826+
'CMutableTxIn',
827+
'CTxOut',
828+
'CMutableTxOut',
829+
'CTransaction',
830+
'CMutableTransaction',
831+
'CBlockHeader',
832+
'CBlock',
833+
'CoreChainParams',
834+
'CoreMainParams',
835+
'CoreTestNetParams',
836+
'CoreRegTestParams',
837+
'CheckTransactionError',
838+
'CheckTransaction',
839+
'CheckBlockHeaderError',
840+
'CheckProofOfWorkError',
841+
'CheckProofOfWork',
842+
'CheckBlockHeader',
843+
'CheckBlockError',
844+
'GetLegacySigOpCount',
845+
'CheckBlock',)

bitcoin/core/key.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,6 @@ def __repr__(self):
176176
else:
177177
return '%s(b%s)' % (self.__class__.__name__, super(CPubKey,
178178
self).__repr__())
179+
180+
181+
__all__ = ('CECKey', 'CPubKey',)

bitcoin/core/script.py

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
is in bitcoin.core.scripteval
1515
"""
1616

17-
from __future__ import absolute_import, division, print_function, unicode_literals
17+
from __future__ import absolute_import, division, print_function
1818

1919
import sys
2020
_bchr = chr
@@ -879,3 +879,146 @@ def SignatureHash(script, txTo, inIdx, hashtype):
879879
if err is not None:
880880
raise ValueError(err)
881881
return h
882+
883+
884+
__all__ = ('MAX_SCRIPT_SIZE',
885+
'MAX_SCRIPT_ELEMENT_SIZE',
886+
'MAX_SCRIPT_OPCODES',
887+
'OPCODE_NAMES',
888+
'CScriptOp',
889+
890+
# every opcode
891+
'OP_0',
892+
'OP_FALSE',
893+
'OP_PUSHDATA1',
894+
'OP_PUSHDATA2',
895+
'OP_PUSHDATA4',
896+
'OP_1NEGATE',
897+
'OP_RESERVED',
898+
'OP_1',
899+
'OP_TRUE',
900+
'OP_2',
901+
'OP_3',
902+
'OP_4',
903+
'OP_5',
904+
'OP_6',
905+
'OP_7',
906+
'OP_8',
907+
'OP_9',
908+
'OP_10',
909+
'OP_11',
910+
'OP_12',
911+
'OP_13',
912+
'OP_14',
913+
'OP_15',
914+
'OP_16',
915+
'OP_NOP',
916+
'OP_VER',
917+
'OP_IF',
918+
'OP_NOTIF',
919+
'OP_VERIF',
920+
'OP_VERNOTIF',
921+
'OP_ELSE',
922+
'OP_ENDIF',
923+
'OP_VERIFY',
924+
'OP_RETURN',
925+
'OP_TOALTSTACK',
926+
'OP_FROMALTSTACK',
927+
'OP_2DROP',
928+
'OP_2DUP',
929+
'OP_3DUP',
930+
'OP_2OVER',
931+
'OP_2ROT',
932+
'OP_2SWAP',
933+
'OP_IFDUP',
934+
'OP_DEPTH',
935+
'OP_DROP',
936+
'OP_DUP',
937+
'OP_NIP',
938+
'OP_OVER',
939+
'OP_PICK',
940+
'OP_ROLL',
941+
'OP_ROT',
942+
'OP_SWAP',
943+
'OP_TUCK',
944+
'OP_CAT',
945+
'OP_SUBSTR',
946+
'OP_LEFT',
947+
'OP_RIGHT',
948+
'OP_SIZE',
949+
'OP_INVERT',
950+
'OP_AND',
951+
'OP_OR',
952+
'OP_XOR',
953+
'OP_EQUAL',
954+
'OP_EQUALVERIFY',
955+
'OP_RESERVED1',
956+
'OP_RESERVED2',
957+
'OP_1ADD',
958+
'OP_1SUB',
959+
'OP_2MUL',
960+
'OP_2DIV',
961+
'OP_NEGATE',
962+
'OP_ABS',
963+
'OP_NOT',
964+
'OP_0NOTEQUAL',
965+
'OP_ADD',
966+
'OP_SUB',
967+
'OP_MUL',
968+
'OP_DIV',
969+
'OP_MOD',
970+
'OP_LSHIFT',
971+
'OP_RSHIFT',
972+
'OP_BOOLAND',
973+
'OP_BOOLOR',
974+
'OP_NUMEQUAL',
975+
'OP_NUMEQUALVERIFY',
976+
'OP_NUMNOTEQUAL',
977+
'OP_LESSTHAN',
978+
'OP_GREATERTHAN',
979+
'OP_LESSTHANOREQUAL',
980+
'OP_GREATERTHANOREQUAL',
981+
'OP_MIN',
982+
'OP_MAX',
983+
'OP_WITHIN',
984+
'OP_RIPEMD160',
985+
'OP_SHA1',
986+
'OP_SHA256',
987+
'OP_HASH160',
988+
'OP_HASH256',
989+
'OP_CODESEPARATOR',
990+
'OP_CHECKSIG',
991+
'OP_CHECKSIGVERIFY',
992+
'OP_CHECKMULTISIG',
993+
'OP_CHECKMULTISIGVERIFY',
994+
'OP_NOP1',
995+
'OP_NOP2',
996+
'OP_NOP3',
997+
'OP_NOP4',
998+
'OP_NOP5',
999+
'OP_NOP6',
1000+
'OP_NOP7',
1001+
'OP_NOP8',
1002+
'OP_NOP9',
1003+
'OP_NOP10',
1004+
'OP_SMALLINTEGER',
1005+
'OP_PUBKEYS',
1006+
'OP_PUBKEYHASH',
1007+
'OP_PUBKEY',
1008+
'OP_INVALIDOPCODE',
1009+
'OPCODES_BY_NAME',
1010+
'DISABLED_OPCODES',
1011+
'CScriptInvalidError',
1012+
'CScriptTruncatedPushDataError',
1013+
'CScript',
1014+
'SCRIPT_VERIFY_P2SH',
1015+
'SCRIPT_VERIFY_STRICTENC',
1016+
'SCRIPT_VERIFY_EVEN_S',
1017+
'SCRIPT_VERIFY_NOCACHE',
1018+
'SIGHASH_ALL',
1019+
'SIGHASH_NONE',
1020+
'SIGHASH_SINGLE',
1021+
'SIGHASH_ANYONECANPAY',
1022+
'FindAndDelete',
1023+
'RawSignatureHash',
1024+
'SignatureHash',)

bitcoin/core/serialize.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
if sys.version > '3':
2525
_bchr = lambda x: bytes([x])
2626
_bord = lambda x: x[0]
27-
from io import BytesIO
27+
from io import BytesIO as _BytesIO
2828
else:
2929
_bchr = chr
3030
_bord = ord
31-
from cStringIO import StringIO as BytesIO
31+
from cStringIO import StringIO as _BytesIO
3232

3333
MAX_SIZE = 0x02000000
3434

@@ -102,7 +102,7 @@ def stream_deserialize(cls, f):
102102

103103
def serialize(self):
104104
"""Serialize, returning bytes"""
105-
f = BytesIO()
105+
f = _BytesIO()
106106
self.stream_serialize(f)
107107
return f.getvalue()
108108

@@ -115,7 +115,7 @@ def deserialize(cls, buf, allow_padding=False):
115115
If allow_padding is False and not all bytes are consumed during
116116
deserialization DeserializationExtraDataError will be raised.
117117
"""
118-
fd = BytesIO(buf)
118+
fd = _BytesIO(buf)
119119
r = cls.stream_deserialize(fd)
120120
if not allow_padding:
121121
padding = fd.read()
@@ -186,13 +186,13 @@ def stream_deserialize(cls, f):
186186

187187
@classmethod
188188
def serialize(cls, obj):
189-
f = BytesIO()
189+
f = _BytesIO()
190190
cls.stream_serialize(obj, f)
191191
return f.getvalue()
192192

193193
@classmethod
194194
def deserialize(cls, buf):
195-
return cls.stream_deserialize(BytesIO(buf))
195+
return cls.stream_deserialize(_BytesIO(buf))
196196

197197

198198
class VarIntSerializer(Serializer):
@@ -332,3 +332,24 @@ def uint256_from_compact(c):
332332
def uint256_to_shortstr(u):
333333
s = "%064x" % (u,)
334334
return s[:16]
335+
336+
337+
__all__ = ('MAX_SIZE',
338+
'Hash',
339+
'Hash160',
340+
'SerializationError',
341+
'SerializationTruncationError',
342+
'DeserializationExtraDataError',
343+
'ser_read',
344+
'Serializable',
345+
'ImmutableSerializable',
346+
'Serializer',
347+
'VarIntSerializer',
348+
'BytesSerializer',
349+
'VectorSerializer',
350+
'uint256VectorSerializer',
351+
'intVectorSerialzer',
352+
'VarStringSerializer',
353+
'uint256_from_str',
354+
'uint256_from_compact',
355+
'uint256_to_shortstr',)

bitcoin/messages.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@
1111

1212
from __future__ import absolute_import, division, print_function, unicode_literals
1313

14+
import hashlib
15+
import random
1416
import struct
1517
import time
16-
import random
18+
19+
# Py3 compatibility
1720
import sys
1821

1922
if sys.version > '3':
20-
import io
23+
_bchr = lambda x: bytes([x])
24+
_bord = lambda x: x[0]
25+
from io import BytesIO as _BytesIO
2126
else:
22-
import cStringIO as io
27+
_bchr = chr
28+
_bord = ord
29+
from cStringIO import StringIO as _BytesIO
2330

2431
# Bad practice, so we have a __all__ at the end; this should be cleaned up
2532
# later.
@@ -46,7 +53,7 @@ def msg_deser(cls, f, protover=PROTO_VERSION):
4653
raise NotImplementedError
4754

4855
def to_bytes(self, params=MainParams()):
49-
f = BytesIO()
56+
f = _BytesIO()
5057
self.msg_ser(f)
5158
body = f.getvalue()
5259
res = params.MESSAGE_START
@@ -64,7 +71,7 @@ def to_bytes(self, params=MainParams()):
6471

6572
@classmethod
6673
def from_bytes(cls, b, protover=PROTO_VERSION):
67-
f = BytesIO(b)
74+
f = _BytesIO(b)
6875
return MsgSerializable.stream_deserialize(f, protover=protover)
6976

7077
@classmethod
@@ -94,7 +101,7 @@ def stream_deserialize(cls, f, params=MainParams(), protover=PROTO_VERSION):
94101
if command in messagemap:
95102
cls = messagemap[command]
96103
# print("Going to deserialize '%s'" % msg)
97-
return cls.msg_deser(BytesIO(msg))
104+
return cls.msg_deser(_BytesIO(msg))
98105
else:
99106
print("Command '%s' not in messagemap" % str(command, 'ascii'))
100107
return None

bitcoin/rpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,6 @@ def addnodeonetry(self, node):
485485

486486
def removenode(self, node):
487487
return self._addnode(node, 'remove')
488+
489+
490+
__all__ = ('JSONRPCException', 'RawProxy', 'Proxy',)

bitcoin/tests/test_scripteval.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import os
1616
import unittest
1717

18+
import sys
19+
if sys.version > '3':
20+
long = int
21+
1822
from binascii import unhexlify
1923

2024
from bitcoin.core import ValidationError

0 commit comments

Comments
 (0)