comparison sat_pubsub/mam.py @ 488:c41f37f1b51c

mam: fix `complete` attribute setting in `onArchiveRequest`
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2022 16:46:04 +0200
parents 7a23db86ee65
children
comparison
equal deleted inserted replaced
487:7a23db86ee65 488:c41f37f1b51c
104 return message 104 return message
105 105
106 def cb(items_data_tuple): 106 def cb(items_data_tuple):
107 items_data, rsm_response = items_data_tuple 107 items_data, rsm_response = items_data_tuple
108 msg_data = [] 108 msg_data = []
109 rsm_elt = None
110 attributes = {} 109 attributes = {}
110 if rsm_response:
111 rsm_elt = rsm_response.toElement()
112 # XXX: we check if it is the last page using initial request data
113 # and RSM element data. In this case, we must have the "complete"
114 # attribute set to "true".
115 page_max = rsm_response.index + mam_request.rsm.max
116 if page_max >= rsm_response.count:
117 # the maximum items which can be displayed is equal to or above the
118 # total number of items, which means we are complete
119 attributes['complete'] = "true"
120 else:
121 rsm_elt = None
111 for item_data in items_data: 122 for item_data in items_data:
112 if item_data.item.name == 'set' and item_data.item.uri == rsm.NS_RSM: 123 if item_data.item.name == 'item':
113 assert rsm_elt is None
114 rsm_elt = item_data.item
115 if rsm_elt.first:
116 # XXX: we check if it is the last page using initial request data
117 # and RSM element data. In this case, we must have the
118 # "complete"
119 # attribute set to "true".
120 page_max = int(rsm_elt.first['index']) + mam_request.rsm.max
121 count = int(str(rsm_elt.count))
122 if page_max >= count:
123 # the maximum items which can be displayed is equal to or
124 # above the total number of items, which means we are complete
125 attributes['complete'] = "true"
126 else:
127 log.msg("WARNING: no <first> element in RSM request: {xml}".format(
128 xml = rsm_elt.toXml().encode('utf-8')))
129 elif item_data.item.name == 'item':
130 msg_data.append([item_data.item['id'], make_message(item_data.item), 124 msg_data.append([item_data.item['id'], make_message(item_data.item),
131 item_data.created]) 125 item_data.created])
132 else: 126 else:
133 log.msg("WARNING: unknown element: {}".format(item_data.item.name)) 127 log.msg("WARNING: unknown element: {}".format(item_data.item.name))
134 if pep: 128 if pep: