This is an automated email from the ASF dual-hosted git repository. astitcher pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit d8ff8f7314f4a046c4033886b92edfc20cd09e72 Author: Andrew Stitcher <astitc...@apache.org> AuthorDate: Tue Apr 22 12:11:21 2025 -0400 PROTON-2892: [Python] Use python library IntFlag for Endpoint state --- python/proton/_endpoints.py | 52 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/python/proton/_endpoints.py b/python/proton/_endpoints.py index d83f7e72f..13b837444 100644 --- a/python/proton/_endpoints.py +++ b/python/proton/_endpoints.py @@ -65,6 +65,7 @@ from ._transport import Transport from ._wrapper import Wrapper from collections.abc import Iterator +from enum import IntFlag from typing import Any, Callable, ClassVar, Optional, Union, TYPE_CHECKING, overload if TYPE_CHECKING: @@ -74,25 +75,11 @@ if TYPE_CHECKING: from ._message import Message -class Endpoint(Wrapper): +class EndpointState(IntFlag): """ - Abstract class from which :class:`Connection`, :class:`Session` - and :class:`Link` are derived, and which defines the state - of these classes. - - The :class:`Endpoint` state is an integral value with flags that + The state of an AMQP endpoint. This is a bit field with flags that encode both the local and remote state of an AMQP Endpoint (:class:`Connection`, :class:`Link`, or :class:`Session`). - The individual bits may be accessed using :const:`LOCAL_UNINIT`, - :const:`LOCAL_ACTIVE`, :const:`LOCAL_CLOSED`, and - :const:`REMOTE_UNINIT`, :const:`REMOTE_ACTIVE`, :const:`REMOTE_CLOSED`. - - Every AMQP endpoint (:class:`Connection`, :class:`Link`, or - :class:`Session`) starts out in an uninitialized state and then - proceeds linearly to an active and then closed state. This - lifecycle occurs at both endpoints involved, and so the state - model for an endpoint includes not only the known local state, - but also the last known state of the remote endpoint. """ LOCAL_UNINIT = PN_LOCAL_UNINIT @@ -113,9 +100,38 @@ class Endpoint(Wrapper): REMOTE_CLOSED = PN_REMOTE_CLOSED """ The remote endpoint state is closed. """ + +class Endpoint(Wrapper): + """ + Abstract class from which :class:`Connection`, :class:`Session` + and :class:`Link` are derived, and which defines the state + of these classes. + + The :class:`Endpoint` state is an integral value with flags that + encode both the local and remote state of an AMQP Endpoint + (:class:`Connection`, :class:`Link`, or :class:`Session`). + The individual bits may be accessed using :const:`LOCAL_UNINIT`, + :const:`LOCAL_ACTIVE`, :const:`LOCAL_CLOSED`, and + :const:`REMOTE_UNINIT`, :const:`REMOTE_ACTIVE`, :const:`REMOTE_CLOSED`. + + Every AMQP endpoint (:class:`Connection`, :class:`Link`, or + :class:`Session`) starts out in an uninitialized state and then + proceeds linearly to an active and then closed state. This + lifecycle occurs at both endpoints involved, and so the state + model for an endpoint includes not only the known local state, + but also the last known state of the remote endpoint. + """ + + LOCAL_UNINIT = EndpointState.LOCAL_UNINIT + REMOTE_UNINIT = EndpointState.REMOTE_UNINIT + LOCAL_ACTIVE = EndpointState.LOCAL_ACTIVE + REMOTE_ACTIVE = EndpointState.REMOTE_ACTIVE + LOCAL_CLOSED = EndpointState.LOCAL_CLOSED + REMOTE_CLOSED = EndpointState.REMOTE_CLOSED + get_condition: ClassVar[Callable[[Any], Any]] get_remote_condition: ClassVar[Callable[[Any], Any]] - get_state: ClassVar[Callable[[Any], int]] + get_state: ClassVar[Callable[[Any], EndpointState]] def __init__(self) -> None: self.condition: Optional['Condition'] = None @@ -133,7 +149,7 @@ class Endpoint(Wrapper): return cond2obj(type(self).get_remote_condition(self._impl)) @property - def state(self) -> int: + def state(self) -> EndpointState: """ The state of the endpoint as a bit field. The state has a local and a remote component. Each of these can be in one of three --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org