def write_update_map(item_name, request_id, issnapshot, events_map): """Encodes and returns a UD3 ('Update By Map') response.""" update = join(str(Method.UD3), 'S', enc_str(item_name), 'S', enc_str(request_id), 'B', enc_bool(issnapshot), append_separator=events_map) if events_map: tokens = [join('S', enc_str(field), _encode_value(value)) for field, value in list(events_map.items())] return update + "|".join(tokens) else: return update
def write_get_items(items=None, exception=None): """Encodes and returns a GIS ('Get Items') response.""" method = str(Method.GIS) if exception: return _handle_exception(exception, join(method, 'E'), ItemsError) if items: return join(method, 'S|') + '|S|'.join( [enc_str(item_name) for item_name in items]) return join(method)
def _encode_value(value): """Encodes a value passed in an update map to be write in ad UD3 response. """ if value is None or isinstance(value, str): return "S|" + enc_str(value) if isinstance(value, bytes): return "Y|" + enc_byte(value) raise RemotingException("Found value '{}' of an unsupported type while " "building a {} request".format( str(value), str(Method.UD3)))
def write_get_schema(fields=None, exception=None): """Encodes and returns a GSC ('Get Items') response.""" method = str(Method.GSC) if exception: return _handle_exception(exception, join(method, 'E'), ItemsError, SchemaError) if fields: return join(method, 'S|') + '|S|'.join( [enc_str(field) for field in fields]) return join(method)
def write_failure(exception): """Encodes and returns a FAL ('Failure') response string.""" return join(str(Method.FAL), 'E', enc_str(str(exception)))
def write_cls(item, request_id): """Encodes and returns a CLS ('Clear Snapshot') response string.""" return join(str(Method.CLS), "S", enc_str(item), "S", enc_str(request_id))
def write_eos(item, request_id): """Encodes and returns an EOS ('End Of Snapshot') response.""" return join(str(Method.EOS), "S", enc_str(item), "S", enc_str(request_id))