Coverage for aiocoap/numbers/__init__.py: 85%
20 statements
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-28 12:34 +0000
« prev ^ index » next coverage.py v7.6.8, created at 2024-11-28 12:34 +0000
1# SPDX-FileCopyrightText: Christian Amsüss and the aiocoap contributors
2#
3# SPDX-License-Identifier: MIT
5"""Module in which all meaningful numbers are collected. Most of the submodules
6correspond to IANA registries.
8The contents of the :mod:`.constants`, :mod:`.types` and :mod:`.codes` modules
9are accessible through this module directly; :mod:`.contentformat`'s and
10:mod:`.optionnumbers`' sole :class:`.contentformat.ContentFormat` and
11:class:`.optionnumbers.OptionNumber` classes are accessible in the same way.
12"""
14import warnings
15import string
17from . import constants, types, codes
18from .contentformat import ContentFormat, _MediaTypes, _MediaTypesRev
19from .optionnumbers import OptionNumber
21# These lists are hard-coded in because static checkers need them explicit. The code below helps keep it up to date.
22# fmt: off
23from .constants import COAPS_PORT, COAP_PORT, MAX_REGULAR_BLOCK_SIZE_EXP, MCAST_ALL, MCAST_IPV4_ALLCOAPNODES, MCAST_IPV6_LINKLOCAL_ALLCOAPNODES, MCAST_IPV6_LINKLOCAL_ALLNODES, MCAST_IPV6_SITELOCAL_ALLCOAPNODES, MCAST_IPV6_SITELOCAL_ALLNODES, SHUTDOWN_TIMEOUT, TransportTuning
24from .types import Type, CON, NON, ACK, RST
25from .codes import Code, EMPTY, GET, POST, PUT, DELETE, FETCH, PATCH, iPATCH, CREATED, DELETED, VALID, CHANGED, CONTENT, CONTINUE, BAD_REQUEST, UNAUTHORIZED, BAD_OPTION, FORBIDDEN, NOT_FOUND, METHOD_NOT_ALLOWED, NOT_ACCEPTABLE, REQUEST_ENTITY_INCOMPLETE, CONFLICT, PRECONDITION_FAILED, REQUEST_ENTITY_TOO_LARGE, UNSUPPORTED_CONTENT_FORMAT, UNPROCESSABLE_ENTITY, TOO_MANY_REQUESTS, INTERNAL_SERVER_ERROR, NOT_IMPLEMENTED, BAD_GATEWAY, SERVICE_UNAVAILABLE, GATEWAY_TIMEOUT, PROXYING_NOT_SUPPORTED, HOP_LIMIT_REACHED, CSM, PING, PONG, RELEASE, ABORT
26__all__ = ['COAPS_PORT', 'COAP_PORT', 'MAX_REGULAR_BLOCK_SIZE_EXP', 'MCAST_ALL', 'MCAST_IPV4_ALLCOAPNODES', 'MCAST_IPV6_LINKLOCAL_ALLCOAPNODES', 'MCAST_IPV6_LINKLOCAL_ALLNODES', 'MCAST_IPV6_SITELOCAL_ALLCOAPNODES', 'MCAST_IPV6_SITELOCAL_ALLNODES', 'SHUTDOWN_TIMEOUT', 'TransportTuning', 'Type', 'CON', 'NON', 'ACK', 'RST', 'Code', 'EMPTY', 'GET', 'POST', 'PUT', 'DELETE', 'FETCH', 'PATCH', 'iPATCH', 'CREATED', 'DELETED', 'VALID', 'CHANGED', 'CONTENT', 'CONTINUE', 'BAD_REQUEST', 'UNAUTHORIZED', 'BAD_OPTION', 'FORBIDDEN', 'NOT_FOUND', 'METHOD_NOT_ALLOWED', 'NOT_ACCEPTABLE', 'REQUEST_ENTITY_INCOMPLETE', 'CONFLICT', 'PRECONDITION_FAILED', 'REQUEST_ENTITY_TOO_LARGE', 'UNSUPPORTED_CONTENT_FORMAT', 'UNPROCESSABLE_ENTITY', 'TOO_MANY_REQUESTS', 'INTERNAL_SERVER_ERROR', 'NOT_IMPLEMENTED', 'BAD_GATEWAY', 'SERVICE_UNAVAILABLE', 'GATEWAY_TIMEOUT', 'PROXYING_NOT_SUPPORTED', 'HOP_LIMIT_REACHED', 'CSM', 'PING', 'PONG', 'RELEASE', 'ABORT', 'OptionNumber', 'ContentFormat']
27# fmt: on
29if __debug__:
30 _generated_all = (
31 constants.__all__
32 + types.__all__
33 + codes.__all__
34 + ["OptionNumber", "ContentFormat"]
35 )
36 if _generated_all != __all__:
37 warnings.warn(f"""Hardcoded __all__ is out of sync (as are imports, probably), please updated to
39 from .constants import {", ".join(constants.__all__)}
40 from .types import {", ".join(types.__all__)}
41 from .codes import {", ".join(codes.__all__)}
42 __all__ = {_generated_all}""")
44media_types = _MediaTypes()
45media_types_rev = _MediaTypesRev()
48def __getattr__(name):
49 if name[0] in string.ascii_uppercase and hasattr(
50 constants._default_transport_tuning, name
51 ):
52 warnings.warn(
53 f"{name} is deprecated, use through the message's transport_tuning instead",
54 DeprecationWarning,
55 stacklevel=2,
56 )
57 return getattr(constants._default_transport_tuning, name)
58 raise AttributeError(f"module {__name__} has no attribute {name}")