def set_filter(self, value, name=constants.STRING_FILTER, descriptor=constants.STRING_FILTER): """Set a filter on the endpoint. Only one filter can be applied to an endpoint. :param value: The filter to apply to the endpoint. Set to None for a NULL filter. :type value: bytes or str or None :param name: The name of the filter. This will be encoded as an AMQP Symbol. By default this is set to b'apache.org:selector-filter:string'. :type name: bytes :param descriptor: The descriptor used if the filter is to be encoded as a described value. This will be encoded as an AMQP Symbol. By default this is set to b'apache.org:selector-filter:string'. Set to None if the filter should not be encoded as a described value. :type descriptor: bytes or None """ value = value.encode(self._encoding) if isinstance( value, six.text_type) else value filter_set = c_uamqp.dict_value() filter_key = c_uamqp.symbol_value(name) filter_value = utils.data_factory(value, encoding=self._encoding) if value is not None and descriptor is not None: descriptor = c_uamqp.symbol_value(descriptor) filter_value = c_uamqp.described_value(descriptor, filter_value) filter_set[filter_key] = filter_value self._address.filter_set = filter_set
def get_filter(self, name=constants.STRING_FILTER): """Get the filter on the source. :param name: The name of the filter. This will be encoded as an AMQP Symbol. By default this is set to b'apache.org:selector-filter:string'. :type name: bytes """ try: filter_key = c_uamqp.symbol_value(name) return self._address.filter_set[filter_key].value except (TypeError, KeyError): return None
def set_filter(self, value, name=constants.STRING_FILTER): """Set a filter on the endpoint. Only one filter can be applied to an endpoint. :param value: The filter to apply to the endpoint. :type value: bytes or str :param name: The name of the filter. This will be encoded as an AMQP Symbol and will also be used as the filter descriptor. By default this is set to b'apache.org:selector-filter:string'. :type name: bytes """ value = value.encode(self._encoding) if isinstance(value, str) else value filter_set = c_uamqp.dict_value() filter_key = c_uamqp.symbol_value(name) descriptor = c_uamqp.symbol_value(name) filter_value = c_uamqp.string_value(value) described_filter_value = c_uamqp.described_value( descriptor, filter_value) self._filters.append((descriptor, filter_value)) filter_set[filter_key] = described_filter_value self._address.filter_set = filter_set
def _c_wrapper(self, value, encoding='UTF-8'): value = value.encode(encoding) if isinstance(value, str) else value return c_uamqp.symbol_value(value)
def test_symbol_value(): value = c_uamqp.symbol_value(b'Test') assert value.value == b'Test' assert value.type == c_uamqp.AMQPType.SymbolValue assert str(value) == "Test"