6565from ._wrapper import Wrapper
6666
6767from collections .abc import Iterator
68+ from enum import IntFlag
6869from typing import Any , Callable , ClassVar , Optional , Union , TYPE_CHECKING , overload
6970
7071if TYPE_CHECKING :
7475 from ._message import Message
7576
7677
77- class Endpoint ( Wrapper ):
78+ class EndpointState ( IntFlag ):
7879 """
79- Abstract class from which :class:`Connection`, :class:`Session`
80- and :class:`Link` are derived, and which defines the state
81- of these classes.
82-
83- The :class:`Endpoint` state is an integral value with flags that
80+ The state of an AMQP endpoint. This is a bit field with flags that
8481 encode both the local and remote state of an AMQP Endpoint
8582 (:class:`Connection`, :class:`Link`, or :class:`Session`).
86- The individual bits may be accessed using :const:`LOCAL_UNINIT`,
87- :const:`LOCAL_ACTIVE`, :const:`LOCAL_CLOSED`, and
88- :const:`REMOTE_UNINIT`, :const:`REMOTE_ACTIVE`, :const:`REMOTE_CLOSED`.
89-
90- Every AMQP endpoint (:class:`Connection`, :class:`Link`, or
91- :class:`Session`) starts out in an uninitialized state and then
92- proceeds linearly to an active and then closed state. This
93- lifecycle occurs at both endpoints involved, and so the state
94- model for an endpoint includes not only the known local state,
95- but also the last known state of the remote endpoint.
9683 """
9784
9885 LOCAL_UNINIT = PN_LOCAL_UNINIT
@@ -113,9 +100,38 @@ class Endpoint(Wrapper):
113100 REMOTE_CLOSED = PN_REMOTE_CLOSED
114101 """ The remote endpoint state is closed. """
115102
103+
104+ class Endpoint (Wrapper ):
105+ """
106+ Abstract class from which :class:`Connection`, :class:`Session`
107+ and :class:`Link` are derived, and which defines the state
108+ of these classes.
109+
110+ The :class:`Endpoint` state is an integral value with flags that
111+ encode both the local and remote state of an AMQP Endpoint
112+ (:class:`Connection`, :class:`Link`, or :class:`Session`).
113+ The individual bits may be accessed using :const:`LOCAL_UNINIT`,
114+ :const:`LOCAL_ACTIVE`, :const:`LOCAL_CLOSED`, and
115+ :const:`REMOTE_UNINIT`, :const:`REMOTE_ACTIVE`, :const:`REMOTE_CLOSED`.
116+
117+ Every AMQP endpoint (:class:`Connection`, :class:`Link`, or
118+ :class:`Session`) starts out in an uninitialized state and then
119+ proceeds linearly to an active and then closed state. This
120+ lifecycle occurs at both endpoints involved, and so the state
121+ model for an endpoint includes not only the known local state,
122+ but also the last known state of the remote endpoint.
123+ """
124+
125+ LOCAL_UNINIT = EndpointState .LOCAL_UNINIT
126+ REMOTE_UNINIT = EndpointState .REMOTE_UNINIT
127+ LOCAL_ACTIVE = EndpointState .LOCAL_ACTIVE
128+ REMOTE_ACTIVE = EndpointState .REMOTE_ACTIVE
129+ LOCAL_CLOSED = EndpointState .LOCAL_CLOSED
130+ REMOTE_CLOSED = EndpointState .REMOTE_CLOSED
131+
116132 get_condition : ClassVar [Callable [[Any ], Any ]]
117133 get_remote_condition : ClassVar [Callable [[Any ], Any ]]
118- get_state : ClassVar [Callable [[Any ], int ]]
134+ get_state : ClassVar [Callable [[Any ], EndpointState ]]
119135
120136 def __init__ (self ) -> None :
121137 self .condition : Optional ['Condition' ] = None
@@ -133,7 +149,7 @@ def remote_condition(self) -> Optional['Condition']:
133149 return cond2obj (type (self ).get_remote_condition (self ._impl ))
134150
135151 @property
136- def state (self ) -> int :
152+ def state (self ) -> EndpointState :
137153 """
138154 The state of the endpoint as a bit field. The state has a local
139155 and a remote component. Each of these can be in one of three
0 commit comments