Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_decoding_unknown_type():
ctx = Context()
pull = ctx.socket(PULL)
push = ctx.socket(PUSH)
pull.bind('inproc://foo')
push.connect('inproc://foo')
push.send(cbor2.dumps(cbor2.CBORTag(4000, None)))
with pytest.raises(IOError):
pull.recv_msg()
push.close()
pull.close()
def default_encoder(encoder, value):
if isinstance(value, dt.timedelta):
encoder.encode(
cbor2.CBORTag(2001, (
value.days, value.seconds, value.microseconds)))
elif value is NoData:
encoder.encode(cbor2.CBORTag(2002, None))
else:
raise cbor2.CBOREncodeError(
'cannot serialize type %s' % value.__class__.__name__)
def cbor2_encoder(encoder, value):
"""
Converts objects of various types to cbor-compatible types.
:param encoder: cbor encoder that should be called
:param value: value to encode
"""
if isinstance(value, Exception):
encoder.encode(CBORTag(_Tags.EXCEPTION.value, encoder.encode_to_bytes({
'type': type(value).__name__,
'dict': value.__dict__
})))
else:
raise ValueError('Encoding of type {} is not supported'.format(type(value).__name__))
def default_encoder(encoder, value):
if isinstance(value, dt.timedelta):
encoder.encode(
cbor2.CBORTag(2001, (
value.days, value.seconds, value.microseconds)))
elif value is NoData:
encoder.encode(cbor2.CBORTag(2002, None))
else:
raise cbor2.CBOREncodeError(
'cannot serialize type %s' % value.__class__.__name__)