Esempio n. 1
0
def write_notify_device_acces(exception=None):
    """Encodes and returns a MDA ('Notify MPN Device Access') response."""
    method = str(Method.MDA)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 2
0
def write_init(exception=None):
    """Encodes and returns a MPI ('Metadata Init') response."""
    if not exception:
        return join(str(Method.MPI), "V")
    else:
        return _handle_exception(exception, join(str(Method.MPI), 'E'),
                                 MetadataProviderError)
Esempio n. 3
0
def write_notify_new_session(exception=None):
    """Encodes and returns a NNS ('Notify User') response."""
    method = str(Method.NNS)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 4
0
def write_notify_user_message(exception=None):
    """Encodes and returns a NUM ('Notify User Message') response."""
    method = str(Method.NUM)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 5
0
def write_notify_new_tables(exception=None):
    """Encodes and returns a NNT ('Notify New Table') response."""
    method = str(Method.NNT)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 6
0
def write_notify_tables_close(exception=None):
    """Encodes and returns a NTC ('Notify Table Close') response."""
    method = str(Method.NTC)
    if not exception:
        return join(method, "V")
    else:
        return _handle_exception(exception, join(method, "E"),
                                 NotificationError)
Esempio n. 7
0
def write_unsub(exception=None):
    """Encodes and returns a USB ('Unsubscribe') response."""
    if not exception:
        return join(str(Method.USB), 'V')
    else:
        return _handle_exception(exception, join(str(Method.USB), 'E'),
                                 SubscribeError,
                                 FailureError)
Esempio n. 8
0
def write_sub(exception=None):
    """Encodes and returns a SUB ('Subscribe') response."""
    if not exception:
        return join(str(Method.SUB), "V")
    else:
        return _handle_exception(exception, join(str(Method.SUB), 'E'),
                                 SubscribeError,
                                 FailureError)
Esempio n. 9
0
def write_device_token_change(exception=None):
    """Reads and parses a MDC ('Notify MPN Subscription Activation') request.
    """
    method = str(Method.MDC)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 10
0
def write_subscription_activation(exception=None):
    """Encodes and returns a MSA ('Notify MPN Subscription Activation')
    response.
    """
    method = str(Method.MSA)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), CreditsError,
                             NotificationError)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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'))
Esempio n. 15
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'))
Esempio n. 16
0
def write_notify_session_close(exception=None):
    """Encodes and returns a NSC ('Notify Session Close') response."""
    method = str(Method.NSC)
    if not exception:
        return join(method, "V")
    return _handle_exception(exception, join(method, "E"), NotificationError)