Ejemplo n.º 1
0
 def encode_amqp_type(amqp_type, test_value):
     """Encode an AMQP type from a stringified test_value"""
     if amqp_type == 'null':
         return None
     if amqp_type == 'boolean':
         return True if test_value == 'True' else False
     if amqp_type == 'ubyte':
         return proton.ubyte(int(test_value, 16))
     if amqp_type == 'ushort':
         return proton.ushort(int(test_value, 16))
     if amqp_type == 'uint':
         return proton.uint(int(test_value, 16))
     if amqp_type == 'ulong':
         return proton.ulong(int(test_value, 16))
     if amqp_type == 'byte':
         return proton.byte(int(test_value, 16))
     if amqp_type == 'short':
         return proton.short(int(test_value, 16))
     if amqp_type == 'int':
         return proton.int32(int(test_value, 16))
     if amqp_type == 'long':
         return _compat.str2long(test_value, 16)
     if amqp_type == 'float':
         return proton.float32(struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0])
     if amqp_type == 'double':
         return struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0]
     if amqp_type == 'decimal32':
         return proton.decimal32(int(test_value[2:], 16))
     if amqp_type == 'decimal64':
         return proton.decimal64(_compat.str2long(test_value[2:], 16))
     if amqp_type == 'decimal128':
         return proton.decimal128(_compat.decode_hex(test_value[2:]))
     if amqp_type == 'char':
         if len(test_value) == 1: # Format 'a'
             return proton.char(test_value)
         return proton.char(_compat.unichr(int(test_value, 16)))
     if amqp_type == 'timestamp':
         return proton.timestamp(int(test_value, 16))
     if amqp_type == 'uuid':
         return uuid.UUID(test_value)
     if amqp_type == 'binary':
         return test_value.encode('utf-8')
     if amqp_type == 'string':
         return _compat.unicode(test_value)
     if amqp_type == 'symbol':
         return proton.symbol(test_value)
     if amqp_type == 'list':
         return AmqpTypesTestSender.encode_amqp_list(test_value)
     if amqp_type == 'map':
         return AmqpTypesTestSender.encode_amqp_map(test_value)
     if amqp_type == 'array':
         #return AmqpTypesTestSender.encode_amqp_array(test_value)
         print('send: Unsupported AMQP type "%s"' % amqp_type)
         return None
     print('send: Unknown AMQP type "%s"' % amqp_type)
     return None
Ejemplo n.º 2
0
 def _create_jms_streammessage(self, test_value_type, test_value, hdr_kwargs, hdr_annotations):
     """Create a JMS stream message"""
     if test_value_type == 'boolean':
         body_list = [test_value == 'True']
     elif test_value_type == 'byte':
         body_list = [proton.byte(int(test_value, 16))]
     elif test_value_type == 'bytes':
         body_list = [base64.b64decode(test_value)]
     elif test_value_type == 'char':
         body_list = [proton.char(base64.b64decode(test_value).decode('utf-8'))]
     elif test_value_type == 'double':
         body_list = [struct.unpack('!d', test_value[2:].decode('hex'))[0]]
     elif test_value_type == 'float':
         body_list = [proton.float32(struct.unpack('!f', test_value[2:].decode('hex'))[0])]
     elif test_value_type == 'int':
         body_list = [proton.int32(int(test_value, 16))]
     elif test_value_type == 'long':
         body_list = [_compat.str2long(test_value, 16)]
     elif test_value_type == 'short':
         body_list = [proton.short(int(test_value, 16))]
     elif test_value_type == 'string':
         body_list = [test_value]
     else:
         raise InteropTestError('JmsSenderShim._create_jms_streammessage: Unknown or unsupported subtype "%s"' %
                                test_value_type)
     return proton.Message(id=(self.sent+1),
                           body=body_list,
                           inferred=True,
                           annotations=JmsHdrsPropsTestSender.merge_dicts(create_annotation('JMS_STREAMMESSAGE_TYPE'),
                                                                          hdr_annotations),
                           **hdr_kwargs)
Ejemplo n.º 3
0
 def _create_jms_mapmessage(self, test_value_type, test_value, name):
     """Create a JMS map message"""
     if test_value_type == 'boolean':
         value = test_value == 'True'
     elif test_value_type == 'byte':
         value = proton.byte(int(test_value, 16))
     elif test_value_type == 'bytes':
         value = test_value.encode('utf-8')
     elif test_value_type == 'char':
         value = proton.char(test_value)
     elif test_value_type == 'double':
         value = struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0]
     elif test_value_type == 'float':
         value = proton.float32(
             struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0])
     elif test_value_type == 'int':
         value = proton.int32(int(test_value, 16))
     elif test_value_type == 'long':
         value = _compat.str2long(test_value, 16)
     elif test_value_type == 'short':
         value = proton.short(int(test_value, 16))
     elif test_value_type == 'string':
         value = test_value
     else:
         raise InteropTestError('JmsMessagesTestSender._create_jms_mapmessage: ' \
                                'Unknown or unsupported subtype "%s"' % test_value_type)
     return proton.Message(
         id=(self.sent + 1),
         body={name: value},
         inferred=False,
         annotations=create_annotation('JMS_MAPMESSAGE_TYPE'))
Ejemplo n.º 4
0
 def _create_jms_streammessage(self, test_value_type, test_value):
     """Create a JMS stream message"""
     if test_value_type == 'boolean':
         body_list = [test_value == 'True']
     elif test_value_type == 'byte':
         body_list = [byte(int(test_value, 16))]
     elif test_value_type == 'bytes':
         body_list = [str(test_value)]
     elif test_value_type == 'char':
         body_list = [char(test_value)]
     elif test_value_type == 'double':
         body_list = [unpack('!d', test_value[2:].decode('hex'))[0]]
     elif test_value_type == 'float':
         body_list = [
             float32(unpack('!f', test_value[2:].decode('hex'))[0])
         ]
     elif test_value_type == 'int':
         body_list = [int32(int(test_value, 16))]
     elif test_value_type == 'long':
         body_list = [long(test_value, 16)]
     elif test_value_type == 'short':
         body_list = [short(int(test_value, 16))]
     elif test_value_type == 'string':
         body_list = [test_value]
     else:
         raise InteropTestError(
             'JmsMessagesTestSender._create_jms_streammessage: Unknown or unsupported subtype "%s"'
             % test_value_type)
     return Message(id=(self.sent + 1),
                    body=body_list,
                    inferred=True,
                    annotations=create_annotation('JMS_STREAMMESSAGE_TYPE'))
Ejemplo n.º 5
0
 def _create_jms_mapmessage(self, test_value_type, test_value, name):
     """Create a JMS map message"""
     if test_value_type == 'boolean':
         value = test_value == 'True'
     elif test_value_type == 'byte':
         value = byte(int(test_value, 16))
     elif test_value_type == 'bytes':
         value = str(test_value)  # remove unicode
     elif test_value_type == 'char':
         value = char(test_value)
     elif test_value_type == 'double':
         value = unpack('!d', test_value[2:].decode('hex'))[0]
     elif test_value_type == 'float':
         value = float32(unpack('!f', test_value[2:].decode('hex'))[0])
     elif test_value_type == 'int':
         value = int32(int(test_value, 16))
     elif test_value_type == 'long':
         value = long(test_value, 16)
     elif test_value_type == 'short':
         value = short(int(test_value, 16))
     elif test_value_type == 'string':
         value = test_value
     else:
         raise InteropTestError(
             'JmsMessagesTestSender._create_jms_mapmessage: Unknown or unsupported subtype "%s"'
             % test_value_type)
     return Message(id=(self.sent + 1),
                    body={name: value},
                    inferred=False,
                    annotations=create_annotation('JMS_MAPMESSAGE_TYPE'))
Ejemplo n.º 6
0
 def _create_jms_mapmessage(self, test_value_type, test_value, name,
                            hdr_kwargs, hdr_annotations):
     """Create a JMS map message"""
     if test_value_type == 'boolean':
         value = test_value == 'True'
     elif test_value_type == 'byte':
         value = proton.byte(int(test_value, 16))
     elif test_value_type == 'bytes':
         value = base64.b64decode(test_value)
     elif test_value_type == 'char':
         value = proton.char(base64.b64decode(test_value).decode('utf-8'))
     elif test_value_type == 'double':
         value = struct.unpack('!d', test_value[2:].decode('hex'))[0]
     elif test_value_type == 'float':
         value = proton.float32(
             struct.unpack('!f', test_value[2:].decode('hex'))[0])
     elif test_value_type == 'int':
         value = proton.int32(int(test_value, 16))
     elif test_value_type == 'long':
         value = int(test_value, 16)
     elif test_value_type == 'short':
         value = proton.short(int(test_value, 16))
     elif test_value_type == 'string':
         value = test_value
     else:
         raise InteropTestError(
             'JmsSenderShim._create_jms_mapmessage: Unknown or unsupported subtype "%s"'
             % test_value_type)
     return proton.Message(id=(self.sent + 1),
                           body={name: value},
                           inferred=False,
                           annotations=JmsHdrsPropsTestSender.merge_dicts(
                               create_annotation('JMS_MAPMESSAGE_TYPE'),
                               hdr_annotations),
                           **hdr_kwargs)
Ejemplo n.º 7
0
 def _create_jms_streammessage(self, test_value_type, test_value):
     """Create a JMS stream message"""
     if test_value_type == 'boolean':
         body_list = [test_value == 'True']
     elif test_value_type == 'byte':
         body_list = [proton.byte(int(test_value, 16))]
     elif test_value_type == 'bytes':
         body_list = [test_value.encode('utf-8')]
     elif test_value_type == 'char':
         body_list = [proton.char(test_value)]
     elif test_value_type == 'double':
         body_list = [
             struct.unpack('!d', _compat.decode_hex(test_value[2:]))[0]
         ]
     elif test_value_type == 'float':
         body_list = [
             proton.float32(
                 struct.unpack('!f', _compat.decode_hex(test_value[2:]))[0])
         ]
     elif test_value_type == 'int':
         body_list = [proton.int32(int(test_value, 16))]
     elif test_value_type == 'long':
         body_list = [_compat.str2long(test_value, 16)]
     elif test_value_type == 'short':
         body_list = [proton.short(int(test_value, 16))]
     elif test_value_type == 'string':
         body_list = [test_value]
     else:
         raise InteropTestError('JmsMessagesTestSender._create_jms_streammessage: ' \
                                'Unknown or unsupported subtype "%s"' %
                                test_value_type)
     return proton.Message(
         id=(self.sent + 1),
         body=body_list,
         inferred=True,
         annotations=create_annotation('JMS_STREAMMESSAGE_TYPE'))
Ejemplo n.º 8
0
 def create_message(self, test_value):
     """
     Creates a single message with the test value translated from its string representation to the appropriate
     AMQP value (set in self.amqp_type).
     """
     if self.amqp_type == 'null':
         return Message(id=(self.sent + 1), body=None)
     elif self.amqp_type == 'boolean':
         return Message(id=(self.sent + 1),
                        body=True if test_value == 'True' else False)
     elif self.amqp_type == 'ubyte':
         return Message(id=(self.sent + 1), body=ubyte(int(test_value, 16)))
     elif self.amqp_type == 'ushort':
         return Message(id=(self.sent + 1),
                        body=ushort(int(test_value, 16)))
     elif self.amqp_type == 'uint':
         return Message(id=(self.sent + 1), body=uint(int(test_value, 16)))
     elif self.amqp_type == 'ulong':
         return Message(id=(self.sent + 1), body=ulong(int(test_value, 16)))
     elif self.amqp_type == 'byte':
         return Message(id=(self.sent + 1), body=byte(int(test_value, 16)))
     elif self.amqp_type == 'short':
         return Message(id=(self.sent + 1), body=short(int(test_value, 16)))
     elif self.amqp_type == 'int':
         return Message(id=(self.sent + 1), body=int32(int(test_value, 16)))
     elif self.amqp_type == 'long':
         return Message(id=(self.sent + 1), body=long(int(test_value, 16)))
     elif self.amqp_type == 'float':
         return Message(id=(self.sent + 1),
                        body=float32(
                            unpack('!f', test_value[2:].decode('hex'))[0]))
     elif self.amqp_type == 'double':
         return Message(id=(self.sent + 1),
                        body=unpack('!d', test_value[2:].decode('hex'))[0])
     elif self.amqp_type == 'decimal32':
         return Message(id=(self.sent + 1),
                        body=decimal32(int(test_value[2:], 16)))
     elif self.amqp_type == 'decimal64':
         l64 = long(test_value[2:], 16)
         return Message(id=(self.sent + 1), body=decimal64(l64))
     elif self.amqp_type == 'decimal128':
         return Message(id=(self.sent + 1),
                        body=decimal128(test_value[2:].decode('hex')))
     elif self.amqp_type == 'char':
         if len(test_value) == 1:  # Format 'a'
             return Message(id=(self.sent + 1), body=char(test_value))
         else:
             val = int(test_value, 16)
             return Message(id=(self.sent + 1), body=char(unichr(val)))
     elif self.amqp_type == 'timestamp':
         return Message(id=(self.sent + 1),
                        body=timestamp(int(test_value, 16)))
     elif self.amqp_type == 'uuid':
         return Message(id=(self.sent + 1), body=UUID(test_value))
     elif self.amqp_type == 'binary':
         return Message(id=(self.sent + 1), body=bytes(test_value))
     elif self.amqp_type == 'string':
         return Message(id=(self.sent + 1), body=unicode(test_value))
     elif self.amqp_type == 'symbol':
         return Message(id=(self.sent + 1), body=symbol(test_value))
     elif self.amqp_type == 'list':
         return Message(id=(self.sent + 1), body=test_value)
     elif self.amqp_type == 'map':
         return Message(id=(self.sent + 1), body=test_value)
     else:
         print 'send: Unsupported AMQP type "%s"' % self.amqp_type
         return None