py/binary: mp_binary_get_size: Raise error on unsupported typecodes.

Previouly, we had errors checked in callers, which led to duplicate code
or missing checks in some places.
This commit is contained in:
Paul Sokolovsky
2017-01-17 22:50:20 +03:00
parent 5e80c53c11
commit af90461931
4 changed files with 17 additions and 7 deletions

View File

@@ -26,7 +26,17 @@ print(struct.calcsize('0s1s0H2H'))
print(struct.unpack('<0s1s0H2H', b'01234'))
print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515))
# check that zero of an unknown type raises an exception
# check that unknown types raise an exception
try:
struct.unpack('z', b'1')
except:
print('Exception')
try:
struct.pack('z', (b'1',))
except:
print('Exception')
try:
struct.calcsize('0z')
except: