Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1963 from danielgtaylor/ddb-binary
Browse files Browse the repository at this point in the history
Require a string value to instantiate Binary DynamoDB type. Fixes #1963, #1956.
  • Loading branch information
danielgtaylor committed Jan 2, 2014
2 parents 46f193f + 151c64e commit e5d30c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions boto/dynamodb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def dynamize_value(val):

class Binary(object):
def __init__(self, value):
if not isinstance(value, basestring):
raise TypeError('Value must be a string of binary data!')

self.value = value

def encode(self):
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/dynamodb/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,17 @@ def test_lossy_float_conversions(self):
self.assertEqual(dynamizer.decode({'NS': ['1.1', '2.2', '3.3']}),
set([1.1, 2.2, 3.3]))


class TestBinary(unittest.TestCase):
def test_bad_input(self):
with self.assertRaises(TypeError):
data = types.Binary(1)

def test_good_input(self):
data = types.Binary(chr(1))

self.assertEqual('\x01', str(data))


if __name__ == '__main__':
unittest.main()

0 comments on commit e5d30c8

Please sign in to comment.