Skip to content

Commit

Permalink
Merge pull request #6 manually
Browse files Browse the repository at this point in the history
Improve error message when the type is not bytes
  • Loading branch information
keis committed Jun 14, 2016
2 parents 600969b + ffbb84f commit 3f9b28c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base58.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
def b58encode(v):
'''Encode a string using Base58'''

if not isinstance(v, bytes):
raise TypeError("a bytes-like object is required, not '%s'" %
type(v).__name__)

origlen = len(v)
v = v.lstrip(b'\0')
newlen = len(v)
Expand Down
6 changes: 6 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ def test_round_trips():
bytes_in = b''.join(bytes_to_test)
bytes_out = b58decode(b58encode(bytes_in))
assert_that(bytes_in, equal_to(bytes_out))


def test_input_should_be_bytes():
data = u'3vQB7B6MrGQZaxCuFg4oH'
with assert_raises(TypeError):
b58encode(data)

0 comments on commit 3f9b28c

Please sign in to comment.