def test_poll_response1(self): poll_response2 = tm10.PollResponse( message_id=tm10.generate_message_id(), # Required in_response_to=tm10.generate_message_id(), # Required - this should be the ID of the corresponding request feed_name='FeedName', # Required inclusive_end_timestamp_label=datetime.datetime.now(tzutc()), # Required inclusive_begin_timestamp_label=datetime.datetime.now(tzutc()), # Optional subscription_id='SubsId001', # Optional message='This is a message.', # Optional content_blocks=[string_content_block1]) # Optional round_trip_message(poll_response2)
def create_poll_response(cls, poll_service, prp, content_blocks): """ :param poll_service: :param prp: :param content_blocks: :return: """ ietl = prp.exclusive_begin_timestamp_label if ietl is not None: ietl += timedelta(milliseconds=1) pr = tm10.PollResponse( message_id=generate_message_id(), in_response_to=prp.message_id, feed_name=prp.collection.name, inclusive_begin_timestamp_label=ietl, inclusive_end_timestamp_label=prp.inclusive_end_timestamp_label) for content_block in content_blocks: pr.content_blocks.append(content_block.to_content_block_10()) return pr
def handle_message(cls, service, request): collection = retrieve_collection(service, request.feed_name, request.message_id) if request.subscription_id: subscription = retrieve_subscription(service, request.subscription_id, request.message_id) if collection.id != subscription.collection_id: details = {SD_ITEM: request.collection_name} raise StatusMessageException(ST_NOT_FOUND, status_details=details, in_response_to=request.message_id) content_bindings = subscription.params.content_bindings else: requested_bindings = parse_content_bindings( request.content_bindings, version=10) content_bindings = collection.get_matching_bindings( requested_bindings) if requested_bindings and not content_bindings: supported_bindings = \ content_binding_entities_to_content_bindings( collection.supported_content, version=10) details = {SD_SUPPORTED_CONTENT: supported_bindings} raise StatusMessageException(ST_UNSUPPORTED_CONTENT_BINDING, in_response_to=request.message_id, status_details=details) # Only Data Feeds existed in TAXII 1.0 if collection.type != collection.TYPE_FEED: message = ("The Named Data Collection is not a Data Feed, " "it is a Data Set. Only Data Feeds can be polled " "in TAXII 1.0") raise StatusMessageException( ST_NOT_FOUND, message=message, status_details={SD_ITEM: request.feed_name}, in_response_to=request.message_id) start, end = (request.exclusive_begin_timestamp_label, request.inclusive_end_timestamp_label) end_response = end or get_utc_now() response = tm10.PollResponse( message_id=generate_message_id(), in_response_to=request.message_id, feed_name=collection.name, #FIXME: exclusive/inclusive clash inclusive_begin_timestamp_label=start, inclusive_end_timestamp_label=end_response, ) content_blocks = service.get_content_blocks( collection, timeframe=(start, end), content_bindings=content_bindings) for block in content_blocks: response.content_blocks.append( content_block_entity_to_content_block(block, version=10)) return response