o
    `j                     @  s:  d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZmZmZmZmZmZ dd
lmZmZ ddlm Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z' ertddl(m)Z) e*e+Z,G dd dZ-G dd dZ.G dd de'e/eZ0G dd de'e/eZ1dS )z,Group management mixin for KafkaAdminClient.    )annotations)EnumN)defaultdict)TYPE_CHECKING)valid_acl_operations)DeleteGroupsRequestDescribeGroupsRequestListGroupsRequest)LeaveGroupRequestOffsetCommitRequestOffsetDeleteRequestOffsetFetchRequest
OffsetSpecOffsetTimestamp)DEFAULT_GENERATION_IDUNKNOWN_MEMBER_ID)ConsumerProtocolAssignmentConsumerProtocolSubscriptionConsumerProtocolType)OffsetAndMetadataTopicPartition)
EnumHelper)KafkaConnectionManagerc                   @  st  e Zd ZU dZded< ded< dd Zdd	 ZdJddZdKddZe	dLddZ
dd ZdMddZdMddZdd Ze	dd ZdJddZdd Zd d! Zd"d# Zd$d% ZdJd&d'ZdJd(d)Ze	d*d+ Ze	d,d- ZdJd.d/ZdJd0d1Ze	d2d3 Ze	d4d5 ZdJd6d7ZdJd8d9Ze	d:d; Ze	d<d= Z dJd>d?Z!dJd@dAZ"e	dBdC Z#e	dDdE Z$	
dJdFdGZ%dJdHdIZ&d
S )NGroupAdminMixinzGMixin providing consumer group management methods for KafkaAdminClient.r   _managerdictconfigc                 C  s   t t|dd}|S )NT)groupsinclude_authorized_operations)r   list)self	group_idsrequest r#   Q/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/kafka/admin/_groups.py_describe_groups_request'   s
   z(GroupAdminMixin._describe_groups_requestc           	      C  s  |j D ]N}|jD ]H}|jr-z	t|j|_W n tjy,   td| d|j	  Y nw |j
rPz	t|j
|_
W q tjyO   td| d|j	  Y qw qqi }|j D ]*}|j}| | }|d}|dd}|rytt||nd|d< |||< qW|S )	z:Process a DescribeGroupsResponse into a group description.z%Unable to decode member_metadata for /z'Unable to decode member_assignment for 
error_codeerror_message Nerror)r   membersmember_metadatar   decodestructr*   logwarning	member_idmember_assignmentr   group_id_process_acl_operationsto_dictpopstrErrorsfor_code)	r    responsegroupmemberresultsr3   resultr'   r(   r#   r#   r$   !_describe_groups_process_response.   s6   




z1GroupAdminMixin._describe_groups_process_responseNc                   s   t t}|d urt|||< n| |I d H }| D ]\}}|| | qi }| D ]\}}| |}	| jj|	|dI d H }
|| 	|
 q.|S Nnode_id)
r   r   _find_coordinator_idsitemsappendr%   r   sendupdater?   r    r!   group_coordinator_idcoordinators_groupscoordinator_idsr3   coordinator_idr=   coordinator_group_idsr"   r:   r#   r#   r$   _async_describe_groupsI   s   
z&GroupAdminMixin._async_describe_groupsFc                 C     | j | j||S )a;  Describe a set of consumer groups.

        Any errors are immediately raised.

        Arguments:
            group_ids: A list of consumer group IDs. These are typically the
                group names as strings.

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the groups' coordinator
                broker. If set to None, it will query the cluster for each group to
                find that group's coordinator. Explicitly specifying this can be
                useful for avoiding extra network round trips if you already know
                the group coordinator. This is only useful when all the group_ids
                have the same coordinator, otherwise it will error. Default: None.

        Returns:
            A dict of {group_id: {key: val}}. key/vals are simple to_dict translations
                of the raw results from DescribeGroupsResponse (with inline decoding
                of ConsumerSubscription and ConsumerAssignment metadata, and conversion
                of acl set ints to semantic enums).
        )r   runrN   )r    r!   rI   r   r#   r#   r$   describe_groupsZ   s   zGroupAdminMixin.describe_groupsc                 C  sR   ddi}| rdd | D |d< d|d< |r"dd |D |d< d	|d< t d
i |S )Nmin_versionr   c                 S     g | ]}t |qS r#   )
GroupState	value_for).0sr#   r#   r$   
<listcomp>y       z8GroupAdminMixin._list_groups_request.<locals>.<listcomp>states_filter   c                 S  rS   r#   )	GroupTyperU   )rV   tr#   r#   r$   rX   |   rY   types_filter   r#   )r	   )rZ   r^   kwargsr#   r#   r$   _list_groups_requestu   s   z$GroupAdminMixin._list_groups_requestc                 C  s4   t |j}|t jur|d|dd |jD S )z3Process a ListGroupsResponse into a list of groups.z,ListGroupsRequest failed with response '{}'.c                 S  s   g | ]}|  qS r#   )r5   rV   r;   r#   r#   r$   rX          zAGroupAdminMixin._list_groups_process_response.<locals>.<listcomp>)r8   r9   r'   NoErrorformatr   )r    r:   
error_typer#   r#   r$   _list_groups_process_response   s   
z-GroupAdminMixin._list_groups_process_responsec                   sf   |d u rdd | j j D }g }|D ]}| j||d}| j j||dI d H }|| | q|S )Nc                 S  s   g | ]}|j qS r#   rA   )rV   brokerr#   r#   r$   rX          z6GroupAdminMixin._async_list_groups.<locals>.<listcomp>)rZ   r^   rA   )r   clusterbrokersra   rF   extendrg   )r    
broker_idsrZ   r^   r   	broker_idr"   r:   r#   r#   r$   _async_list_groups   s   z"GroupAdminMixin._async_list_groupsc                 C     | j | j|||S )a  List all consumer groups known to the cluster.

        This returns a list of Group dicts. The tuples are
        composed of the consumer group name and the consumer group protocol
        type.

        Only consumer groups that store their offsets in Kafka are returned.
        The protocol type will be an empty string for groups created using
        Kafka < 0.9 APIs because, although they store their offsets in Kafka,
        they don't use Kafka for group coordination. For groups created using
        Kafka >= 0.9, the protocol type will typically be "consumer".

        As soon as any error is encountered, it is immediately raised.

        Keyword Arguments:
            broker_ids ([int], optional): A list of broker node_ids to query for consumer
                groups. If set to None, will query all brokers in the cluster.
                Explicitly specifying broker(s) can be useful for determining which
                consumer groups are coordinated by those broker(s). Default: None
            states_filter (list, optional): Filter groups by state. Values
                may be :class:`GroupState` members, their string names
                (case-insensitive, hyphen or underscore), or raw protocol
                strings (e.g. ``['Stable', 'Empty']``). Requires broker
                >= 3.0 (KIP-518). Default: None (no filter).
            types_filter (list, optional): Filter groups by type. Values
                may be :class:`GroupType` members, their string names
                (case-insensitive), or raw protocol strings (e.g.
                ``['consumer', 'classic', 'share']``). Requires broker
                >= 4.0 (KIP-848). Default: None (no filter).

        Returns:
            List of group data dicts, with key/vals from ListGroupsRequest
        )r   rP   ro   )r    rm   rZ   r^   r#   r#   r$   list_groups   s   "zGroupAdminMixin.list_groupsc                 #  s   t j}t j}|j d}g }| D ]1\}}|d u rd }ntt}	|D ]\}
}|	|
 | q# fdd|	 D }||||d qt	|dkrNt
d| jjt dk ru|D ]}|jd u rbdnd}|jt |j|j||dfV  qYd S d t |d|d	fV  d S )
N   c                   s    g | ]\}} |t |d qS ))namepartition_indexes)r   rV   rs   parts_GroupTopicr#   r$   rX      s    z@GroupAdminMixin._list_group_offsets_requests.<locals>.<listcomp>r3   topicsr   zEmpty group_specs!   )r3   rz   rR   max_version)r   rR   r|   )r   OffsetFetchRequestTopicOffsetFetchRequestGroupOffsetFetchRequestTopicsrD   r   setaddrE   len
ValueErrorr   broker_version_dataapi_versionrz   r3   )r    group_specs_Topic_Groupr|   r   r3   
partitionsgroup_topicstopics_partitionstopic	partitionr;   rR   r#   rw   r$   _list_group_offsets_requests   s>   

z,GroupAdminMixin._list_group_offsets_requestsc                 C  s   t | j}|t jur|d| ji }| jD ].}|jD ](}t|j	|j
}t |j}|t jur9|d|j t|j|j|jd||< qq|S )zbBuild {TopicPartition: OffsetAndMetadata} from an OffsetFetchResponse or OffsetFetchResponseGroup.z*OffsetFetchResponse failed for group '{}'.z)OffsetFetchResponse failed for partition offsetmetadataleader_epoch)r8   r9   r'   rd   re   r3   rz   r   r   rs   partition_indexr   r   committed_offsetr   committed_leader_epoch)r;   rf   r=   r   r   tppartition_errorr#   r#   r$   _parse_group_offsets   s*   





z$GroupAdminMixin._parse_group_offsetsc                   sP   t |j}|t jur|d||jdkr! fdd|jD S | |iS )zProcess an OffsetFetchResponse.z.OffsetFetchResponse failed with response '{}'.rr   c                   s   i | ]	}|j  |qS r#   )r3   r   rb   r    r#   r$   
<dictcomp>   s    zHGroupAdminMixin._list_group_offsets_process_response.<locals>.<dictcomp>)r8   r9   r'   rd   re   API_VERSIONr   r   )r    r:   r3   rf   r#   r   r$   $_list_group_offsets_process_response   s   


z4GroupAdminMixin._list_group_offsets_process_responsec                   s   t t}| t I d H }| D ]\}}|| | qi }tj}|j}| D ]*\}}	|  fdd|	D D ]\}}
| j	j
|
|dI d H }|| j||d q;q+|S )Nc                   s   i | ]}| | qS r#   r#   rV   r3   r   r#   r$   r     s    z=GroupAdminMixin._async_list_group_offsets.<locals>.<dictcomp>rA   )r3   )r   r   rC   rD   rE   r   r~   r   r   r   rF   rG   r   )r    r   rJ   rK   r3   rL   r=   r   rx   r!   r"   r:   r#   r   r$   _async_list_group_offsets  s    z)GroupAdminMixin._async_list_group_offsetsc                 C  s<   t |trdd |D }n	t |tr|di}| j| j|S )a  Fetch committed offsets for one or more consumer groups.

        On brokers supporting OffsetFetch v8+ (Apache Kafka 3.0+, KIP-709), this
        issues a single OffsetFetch per coordinator covering all groups
        hosted by that coordinator. On older brokers it currently only supports
        one consumer group (per coordinator).

        Arguments:
            group_specs (dict): Mapping of group_id (str) to either a list of
                :class:`~kafka.TopicPartition` to fetch, or None to fetch all
                committed offsets for that group.
                Or, one or more group_id (str or list[str]) to fetch all offsets
                for each group.

        Returns:
            A dict mapping group_id (str) to a dict mapping
                :class:`~kafka.TopicPartition` to
                :class:`~kafka.structs.OffsetAndMetadata`.

        Raises:
            UnsupportedVersionError: if multiple groups are requested against
                a broker that does not support OffsetFetch v8+; or if group_spec
                with value None against a broker that does not support
                OffsetFetch v2+.
            BrokerResponseError: as soon as any group- or partition-level error
                is encountered.
        c                 S  s   i | ]}|d qS Nr#   r   r#   r#   r$   r   /  ri   z6GroupAdminMixin.list_group_offsets.<locals>.<dictcomp>N)
isinstancer   r7   r   rP   r   )r    r   r#   r#   r$   list_group_offsets  s
   

z"GroupAdminMixin.list_group_offsetsc                 C  s
   t |dS )N)groups_names)r   )r    r!   r#   r#   r$   _delete_groups_request6  s   
z&GroupAdminMixin._delete_groups_requestc                 C  s>   g }|j D ]\}}|dkrdnt|j}|||f q|S )zParse a DeleteGroupsResponse.r   OK)r=   r8   r9   __name__rE   )r    r:   r=   r3   r'   resr#   r#   r$   _convert_delete_groups_response9  s
   z/GroupAdminMixin._convert_delete_groups_responsec                   s   t t}|d ur|||< n| |I d H }| D ]\}}|| | qg }| D ]\}}| |}	| jj|	|dI d H }
|| 	|
 q,t
|S r@   )r   r   rC   rD   rE   r   r   rF   rl   r   r   rH   r#   r#   r$   _async_delete_groupsA  s   

z$GroupAdminMixin._async_delete_groupsc                 C  rO   )a|  Delete Group Offsets for given consumer groups.

        Note:
        This does not verify that the group ids actually exist and
        group_coordinator_id is the correct coordinator for all these groups.

        The result needs checking for potential errors.

        Arguments:
            group_ids ([str]): The consumer group ids of the groups which are to be deleted.

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the broker which is
                the coordinator for all the groups. Default: None.

        Returns:
            A list of tuples (group_id, KafkaError)
        )r   rP   r   )r    r!   rI   r#   r#   r$   delete_groupsQ  s   zGroupAdminMixin.delete_groupsc              	     s   t j  j}tt}| D ]\}}||j ||j|j	|j
d u r#dn|j
|jd qt | ttd d fdd| D ddS )N)r   r   r   committed_metadatac                      g | ]
\}} ||d qS )rs   r   r#   ru   r   r#   r$   rX   z      z@GroupAdminMixin._alter_group_offsets_request.<locals>.<listcomp>rr   )r3   generation_id_or_member_epochr1   group_instance_idretention_time_msrz   r|   )r   OffsetCommitRequestTopicOffsetCommitRequestPartitionr   r   rD   r   rE   r   r   r   r   r   r   )r3   offsets
_Partitiontopic2partitionsr   oamr#   r   r$   _alter_group_offsets_requesth  s*   

z,GroupAdminMixin._alter_group_offsets_requestc                 C  s:   i }| j D ]}|jD ]}t|j|t|j|j< q
q|S r   )rz   r   r8   r9   r'   r   rs   r   )r:   r=   r   r   r#   r#   r$   %_alter_group_offsets_process_response  s   


z5GroupAdminMixin._alter_group_offsets_process_responsec                   N   |si S |d u r|  |I d H }| ||}| jj||dI d H }| |S r@   )_find_coordinator_idr   r   rF   r   )r    r3   r   rI   r"   r:   r#   r#   r$   _async_alter_group_offsets     
z*GroupAdminMixin._async_alter_group_offsetsc                 C  rp   )az  Alter committed offsets for a consumer group.

        The group must have no active members (i.e. be empty or dead) for
        the commit to succeed; otherwise individual partitions may return
        ``UNKNOWN_MEMBER_ID`` or similar errors.

        Arguments:
            group_id (str): The consumer group id.
            offsets (dict): A dict mapping :class:`~kafka.TopicPartition` to
                :class:`~kafka.structs.OffsetAndMetadata`.

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the group's
                coordinator broker. If None, the cluster will be queried to
                locate the coordinator. Default: None.

        Returns:
            dict: A dict mapping :class:`~kafka.TopicPartition` to the
            partition-level :class:`~kafka.errors.KafkaError` class
            (``NoError`` on success).
        )r   rP   r   )r    r3   r   rI   r#   r#   r$   alter_group_offsets  s   
z#GroupAdminMixin.alter_group_offsetsc                 C  sJ   i }| j D ]}|jD ]}t|j|j}t|j|| jd||< q
q|S )N)r*   r   )	rz   r   r   rs   r   r8   r9   r'   r   )r:   to_resetr=   r   r   r   r#   r#   r$   %_reset_group_offsets_process_response  s   


z5GroupAdminMixin._reset_group_offsets_process_responsec                 C  s$   | dk s| |kr
|S | |k r|S | S )Nr   r#   )rawearliestlatestr#   r#   r$   _clamp_offset  s
   zGroupAdminMixin._clamp_offsetc                   s  |si S t | }i }t| D ]#\}}t|ttfrqt|tr,||||< qt	d| d|d|d u rC| 
|I d H }| |t|iI d H | }| dd |D I d H }	| dd |D I d H }
i }|rw| |I d H }i }|D ]5}||v r|| j}n|| }| ||	| j|
| j}||v r|| j|d||< q{t|dd d	||< q{| ||}| jj||d
I d H }| ||S )NzUnsupported reset target for z: z6 (expected OffsetSpec, OffsetTimestamp, or int offset)c                 S     i | ]}|t jqS r#   )r   EARLIESTrV   r   r#   r#   r$   r     rc   z>GroupAdminMixin._async_reset_group_offsets.<locals>.<dictcomp>c                 S  r   r#   )r   LATESTr   r#   r#   r$   r     rc   )r   r)   r   rA   )r   keysr   rD   r   r   r   intr6   	TypeErrorr   r   _async_list_partition_offsetsr   r   _replacer   r   r   rF   r   )r    r3   offset_specsrI   all_tpsexplicit_offsetsr   valcurrentr   r   r   r   r   clampedr"   r:   r#   r#   r$   _async_reset_group_offsets  sB   
z*GroupAdminMixin._async_reset_group_offsetsc                 C  rp   )a  Reset committed offsets for a consumer group.

        The group must have no active members (i.e. be empty or dead) for
        the reset to succeed; otherwise individual partitions may return
        ``UNKNOWN_MEMBER_ID`` or similar errors.

        Each dict value selects how the target offset is produced. All
        resulting offsets are clamped to the partition's
        ``[earliest, latest]`` range; values that resolve to
        ``UNKNOWN_OFFSET`` (e.g. a timestamp beyond the last record) are
        clamped to ``latest``.

        Arguments:
            group_id (str): The consumer group id.
            offset_specs (dict): A dict mapping :class:`~kafka.TopicPartition` to
                one of:

                * :class:`~kafka.admin.OffsetSpec` (e.g. ``OffsetSpec.EARLIEST``,
                  ``OffsetSpec.LATEST``, ``OffsetSpec.MAX_TIMESTAMP``):
                  resolved server-side via ListOffsets.
                * :class:`~kafka.admin.OffsetTimestamp` (ms since epoch):
                  resolved server-side to the earliest offset whose timestamp
                  is ``>=`` the given value.
                * Plain ``int``: an explicit committed offset (no server-side
                  resolution), which is still clamped to the valid range.

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the group's
                coordinator broker. If None, the cluster will be queried to
                locate the coordinator. Default: None.

        Returns:
            dict: A dict mapping :class:`~kafka.TopicPartition` to dict of
            {'error': :class:`~kafka.errors.KafkaError` class, 'offset': int}.
            The ``offset`` value is the post-clamp value that was committed.
        )r   rP   r   )r    r3   r   rI   r#   r#   r$   reset_group_offsets  s   %
z#GroupAdminMixin.reset_group_offsetsc                   sT   t j  j}tt}|D ]}||j ||jd qt |  fdd| D dS )N)r   c                   r   r   r#   ru   r   r#   r$   rX     r   zAGroupAdminMixin._delete_group_offsets_request.<locals>.<listcomp>ry   )	r   OffsetDeleteRequestTopicOffsetDeleteRequestPartitionr   r   r   rE   r   rD   )r3   r   r   r   r   r#   r   r$   _delete_group_offsets_request  s   


z-GroupAdminMixin._delete_group_offsets_requestc                 C  s^   t | j}|t jur|d| i }| jD ]}|jD ]}t |j|t|j|j	< qq|S )Nz.OffsetDeleteRequest failed with response '{}'.)
r8   r9   r'   rd   re   rz   r   r   rs   r   )r:   	top_levelr=   r   r   r#   r#   r$   &_delete_group_offsets_process_response#  s   



z6GroupAdminMixin._delete_group_offsets_process_responsec                   r   r@   )r   r   r   rF   r   )r    r3   r   rI   r"   r:   r#   r#   r$   _async_delete_group_offsets0  r   z+GroupAdminMixin._async_delete_group_offsetsc                 C  rp   )a  Delete committed offsets for a consumer group.

        The group must have no active members subscribed to the given topics;
        otherwise partitions may fail with ``GROUP_SUBSCRIBED_TO_TOPIC``.

        Arguments:
            group_id (str): The consumer group id.
            partitions: An iterable of :class:`~kafka.TopicPartition` whose
                committed offsets should be deleted.

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the group's
                coordinator broker. If None, the cluster will be queried to
                locate the coordinator. Default: None.

        Returns:
            dict: A dict mapping :class:`~kafka.TopicPartition` to the
            partition-level :class:`~kafka.errors.KafkaError` class
            (``NoError`` on success).

        Raises:
            KafkaError: If the response contains a top-level error (e.g.
                ``GroupIdNotFoundError``, ``NonEmptyGroupError``).
        )r   rP   r   )r    r3   r   rI   r#   r#   r$   delete_group_offsets9  s   
z$GroupAdminMixin.delete_group_offsetsc                 C  sf   t j}g }|D ]#}|jd ur|jnd|jd}|dkr |j|d< ||di | qt | |d|dS )Nr)   )r1   r   r_   reason   )r3   r+   rR   r|   r#   )r
   MemberIdentityr1   r   r   rE   )r3   r+   version_Member
identitiesmr`   r#   r#   r$   #_remove_group_members_batch_requestW  s   
z3GroupAdminMixin._remove_group_members_batch_requestc                 C  s4   t | j}|t jur|d| dd | jD S )Nz,LeaveGroupRequest failed with response '{}'.c                 S  s"   i | ]}|j p	|jt|jqS r#   )r1   r   r8   r9   r'   )rV   r   r#   r#   r$   r   p  s    zPGroupAdminMixin._remove_group_members_process_batch_response.<locals>.<dictcomp>)r8   r9   r'   rd   re   r+   )r:   r   r#   r#   r$   ,_remove_group_members_process_batch_responsej  s   
z<GroupAdminMixin._remove_group_members_process_batch_responsec           
        s   |si S |d u r|  |I d H }| jjt}|dk}|r5| |||}| jj||dI d H }| |S i }|D ]2}	|	jd urEt	
d|	jsLtdt||	jdd}| jj||dI d H }t	|j||	jpj|	j< q9|S )Nr   rA   zdBroker does not support removing members by group.instance.id; requires LeaveGroup v3+ (Kafka 2.3+).zbMemberToRemove.member_id is required when broker does not support batched LeaveGroupRequest (v3+).r{   )r3   r1   r|   )r   r   r   r   r
   r   rF   r   r   r8   UnsupportedVersionErrorr1   r   r9   r'   )
r    r3   r+   rI   r   batch_supportedr"   r:   r=   r   r#   r#   r$   _async_remove_group_membersu  s>   

z+GroupAdminMixin._async_remove_group_membersc                 C  rp   )a  Remove members from a consumer group.

        On brokers supporting LeaveGroup v3+ (Kafka 2.3+), a single batched
        request is sent. On older brokers, falls back to one single-member
        LeaveGroupRequest per member (in which case ``group_instance_id`` is
        not supported and ``member_id`` is required).

        Arguments:
            group_id (str): The consumer group id.
            members: An iterable of :class:`~kafka.admin.MemberToRemove`.
                Each entry must set at least one of ``member_id`` or,
                if brokers support LeaveGroup v3+, ``group_instance_id``.
                ``reason`` is only sent to brokers supporting
                LeaveGroup v5+ (KIP-800).

        Keyword Arguments:
            group_coordinator_id (int, optional): The node_id of the group's
                coordinator broker. If None, the cluster will be queried to
                locate the coordinator. Default: None.

        Returns:
            dict: A dict mapping :class:`~kafka.admin.MemberToRemove` to the
            per-member :class:`~kafka.errors.KafkaError` class
            (``NoError`` on success). The key's ``reason`` is always None in
            the result (not echoed by the broker).

        Raises:
            KafkaError: If a batched response contains a top-level error.
            UnsupportedVersionError: If the broker does not support batched
                LeaveGroupRequest and any member uses ``group_instance_id``.
        )r   rP   r   )r    r3   r+   rI   r#   r#   r$   remove_group_members  s    
z$GroupAdminMixin.remove_group_membersr   )NF)NNNNN)'r   
__module____qualname____doc____annotations__r%   r?   rN   rQ   staticmethodra   rg   ro   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   r#   r#   r$   r       s`   
 



	
'#

$





	



+*



	


#r   c                   @  s6   e Zd ZdZdZdddZdd Zdd	 Zd
d ZdS )MemberToRemovea  A consumer group member to remove via Admin.remove_group_members

    At least one of ``member_id`` (identifying a dynamic group member)
    or ``group_instance_id`` (identifying a static group member) must be set.

    Keyword Arguments:
        member_id (str or None): The dynamic member id (as assigned by the
            coordinator in JoinGroupResponse). Use None for static-only removal.
        group_instance_id (str or None): The static member instance id (the
            ``group.instance.id`` configured on the member). Requires LeaveGroup
            v3+ (Kafka 2.3+).
        reason (str or None): Optional reason for removal (propagated to the
            broker on LeaveGroup v5+; ignored on older brokers).
    r1   r   r   Nc                 C  s   || _ || _|| _d S r   r   )r    r1   r   r   r#   r#   r$   __init__  s   
zMemberToRemove.__init__c                 C  s   d | j| j| jS )Nz><MemberToRemove member_id={}, group_instance_id={}, reason={}>)re   r1   r   r   r   r#   r#   r$   __repr__  s   zMemberToRemove.__repr__c                 C  s&   t | j|jk| j|jk| j|jkfS r   )allr1   r   r   )r    otherr#   r#   r$   __eq__  s
   


zMemberToRemove.__eq__c                 C  s   t | j| j| jfS r   )hashr1   r   r   r   r#   r#   r$   __hash__  s   zMemberToRemove.__hash__r   )	r   r   r   r   	__slots__r   r   r   r   r#   r#   r#   r$   r     s    
r   c                   @  s0   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )rT   zCConsumer group states as reported by the broker (KIP-518, KIP-848).UnknownPreparingRebalanceCompletingRebalanceStableDeadEmpty	AssigningReconcilingN)r   r   r   r   UNKNOWNPREPARING_REBALANCECOMPLETING_REBALANCESTABLEDEADEMPTY	ASSIGNINGRECONCILINGr#   r#   r#   r$   rT     s    rT   c                   @  s    e Zd ZdZdZdZdZdZdS )r\   z(Consumer group protocol types (KIP-848).r   classicconsumershareN)r   r   r   r   r  CLASSICCONSUMERSHAREr#   r#   r#   r$   r\     s    r\   )2r   
__future__r   enumr   	itertoolsloggingcollectionsr   r.   typingr   kafka.errorserrorsr8   kafka.admin._aclsr   kafka.protocol.adminr   r   r	   kafka.protocol.consumerr
   r   r   r   r   r   kafka.protocol.consumer.groupr   r    kafka.protocol.consumer.metadatar   r   r   kafka.structsr   r   
kafka.utilr   kafka.net.managerr   	getLoggerr   r/   r   r   r7   rT   r\   r#   r#   r#   r$   <module>   s8     
     !%