Exemplo n.º 1
0
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
Exemplo n.º 2
0
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)))
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def write_failure(exception):
    """Encodes and returns a FAL ('Failure') response string."""
    return join(str(Method.FAL), 'E', enc_str(str(exception)))
Exemplo n.º 6
0
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))
Exemplo n.º 7
0
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))