Beispiel #1
0
def write_notiy_user(method, allowed_max_bandwidth=None,
                     wants_tables_notification=None, exception=None):
    """Encodes and returns a NUS ('Notify User') response."""
    if not exception:
        return join(str(method),
                    'D', enc_double(allowed_max_bandwidth),
                    'B', enc_bool(wants_tables_notification))
    else:
        return _handle_exception(exception, join(str(method), 'E'),
                                 AccessError, CreditsError)
Beispiel #2
0
def write_get_item_data(items_data=None, exception=None):
    """Encodes and returns a GIT ('Get Item Data') response."""
    method = str(Method.GIT.name)
    if not exception:
        if items_data:
            encoded_items = [
                join('I', enc_int(data["distinctSnapshotLength"]), 'D',
                     enc_double(data["minSourceFrequency"]), 'M',
                     enc_modes(data["allowedModeList"])) for data in items_data
            ]
            return join(method, append_separator=True) + \
                "|".join(encoded_items)
        return join(method)
    return _handle_exception(exception, join(method, 'E'))
Beispiel #3
0
def write_get_user_item_data(items_data=None, exception=None):
    """Encodes and returns a GUI ('Get User Item Data') response."""
    method = str(Method.GUI)
    if not exception:
        if items_data:
            encoded_items = [
                join('I', enc_int(data["allowedBufferSize"]), 'D',
                     enc_double(data["allowedMaxFrequency"]), 'M',
                     enc_modes(data["allowedModeList"])) for data in items_data
            ]

            return join(method, append_separator=True) + \
                "|".join(encoded_items)
        return join(method)
    return _handle_exception(exception, join(method, 'E'))