
    Vh%                         d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ  G d	 d
      Z G d d      Z G d d      Z G d de	j(                        Zy)zyInstance Messenger base classes for protocol support.

You will find these useful if you're adding a new protocol to IM.
    )Type)error)ProtocolconnectionDone)styles)FailureprefixedMethods)OFFLINEOfflineErrorc                   B    e Zd Zd Zd Zd Zd Zd ZdefdZ	defdZ
y	)
AbstractGroupc                      || _         || _        y N)nameaccount)selfr   r   s      L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/im/basesupport.py__init__zAbstractGroup.__init__   s    	    c                     t        | d      S )zfinds group commands

        these commands are methods on me that start with imgroup_; they are
        called with no arguments
        imgroup_r	   r   s    r   getGroupCommandszAbstractGroup.getGroupCommands   s     tZ00r   c                     t        | d      S )a(  finds group commands

        these commands are methods on me that start with imgroup_; they are
        called with a user present within this room as an argument

        you may want to override this in your group in order to filter for
        appropriate commands on the given user
        	imtarget_r	   )r   targets     r   getTargetCommandszAbstractGroup.getTargetCommands#   s     t[11r   c                     | j                   j                  st        | j                   j                  j                  | j                         y r   )r   clientr   	joinGroupr   r   s    r   joinzAbstractGroup.join.   s1    ||""%%dii0r   c                     | j                   j                  st        | j                   j                  j                  | j                         y r   )r   r    r   
leaveGroupr   r   s    r   leavezAbstractGroup.leave3   s1    ||""&&tyy1r   returnc                 <    d| j                    d| j                  dS )N< >)	__class__r   r   s    r   __repr__zAbstractGroup.__repr__8   s     4>>"!DII=22r   c                 L    | j                    d| j                  j                   S N@r   r   accountNamer   s    r   __str__zAbstractGroup.__str__;   "    ))Adll66788r   N)__name__
__module____qualname__r   r   r   r"   r%   strr,   r2    r   r   r   r      s3    1	21
2
3# 39 9r   r   c                   6    e Zd Zd Zd Zd ZdefdZdefdZy)AbstractPersonc                 6    || _         || _        t        | _        y r   )r   r   r   status)r   r   baseAccounts      r   r   zAbstractPerson.__init__@   s    	"r   c                     t        | d      S )zfinds person commands

        these commands are methods on me that start with imperson_; they are
        called with no arguments
        	imperson_r	   r   s    r   getPersonCommandsz AbstractPerson.getPersonCommandsE   s     t[11r   c                      y)z#
        Returns a string.
        z--r8   r   s    r   getIdleTimezAbstractPerson.getIdleTimeM   s     r   r&   c                 V    d| j                    d| j                  d| j                   dS )Nr(   r)   /r*   )r+   r   r<   r   s    r   r,   zAbstractPerson.__repr__S   s*    4>>"!DII=$++a@@r   c                 L    | j                    d| j                  j                   S r.   r0   r   s    r   r2   zAbstractPerson.__str__V   r3   r   N)	r4   r5   r6   r   r@   rB   r7   r,   r2   r8   r   r   r:   r:   ?   s+    
2A# A9 9r   r:   c                   L    e Zd ZU dZdZee   ed<   d Zd Z	e
fdeddfdZd	 Zy)
AbstractClientMixinzDesigned to be mixed in to a Protocol implementing class.

    Inherit from me first.

    @ivar _logonDeferred: Fired when I am done logging in.
    N
_protoBasec                     | j                   j                  D ]%  }t        |t              s|| j                   _         n 	 || _        || _        || _        y r   )r+   	__bases__
issubclassr   rH   r   chat_logonDeferred)r   r   chatuilogonDeferredbases        r   r   zAbstractClientMixin.__init__d   sO    NN,, 	D$),0)	
 	+r   c                 :    | j                   j                  |        y r   )rH   connectionMader   s    r   rR   z"AbstractClientMixin.connectionMadeo   s    &&t,r   reasonr&   c                     | j                   j                  | |       | j                          | j                  j	                  | |      S r   )r   _clientLostunregisterAsAccountClientrH   connectionLostr   rS   s     r   rW   z"AbstractClientMixin.connectionLostr   s9      v.&&(--dF;;r   c                 :    | j                   j                  |        y)z*Tell the chat UI that I have `signed off'.N)rL   unregisterAccountClientr   s    r   rV   z-AbstractClientMixin.unregisterAsAccountClientw   s    		))$/r   )r4   r5   r6   __doc__rH   r   r   __annotations__r   rR   r   r   rW   rV   r8   r   r   rG   rG   Z   s>     "&JX%	,- 0> <W <$ <
0r   rG   c                   v    e Zd ZdZdZdZdZeZe	Z
dZd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZdefdZy)AbstractAccounta  Base class for Accounts.

    I am the start of an implementation of L{IAccount<interfaces.IAccount>}, I
    implement L{isOnline} and most of L{logOn}, though you'll need to implement
    L{_startLogOn} in a subclass.

    @cvar _groupFactory: A Callable that will return a L{IGroup} appropriate
        for this account type.
    @cvar _personFactory: A Callable that will return a L{IPerson} appropriate
        for this account type.

    @type _isConnecting: boolean
    @ivar _isConnecting: Whether I am in the process of establishing a
    connection to the server.
    @type _isOnline: boolean
    @ivar _isOnline: Whether I am currently on-line with the server.

    @ivar accountName:
    @ivar autoLogin:
    @ivar username:
    @ivar password:
    @ivar host:
    @ivar port:
    r   N   c                 t    || _         || _        || _        || _        || _        || _        i | _        i | _        y r   )r1   	autoLoginusernamepasswordhostport_groups_persons)r   r1   ra   rb   rc   rd   re   s          r   r   zAbstractAccount.__init__   s;    &"  		r   c                 F    dD ]  }t        | |      rt        | |i         y )N)rf   rg   )hasattrsetattr)r   ks     r   upgrateToVersion2z!AbstractAccount.upgrateToVersion2   s'    ( 	%A4#a$	%r   c                 x    t         j                  j                  |       }dD ]  }	 ||=  |S # t        $ r Y w xY w)N)r    	_isOnline_isConnecting)r   	Versioned__getstate__KeyError)r   staterk   s      r   rq   zAbstractAccount.__getstate__   sN      --d39 	A!H	
   s   -	99c                     | j                   S r   )rn   r   s    r   isOnlinezAbstractAccount.isOnline   s    ~~r   c                 2   | j                   sw| j                  skd| _         | j                  |      }|j                  | j                         |j                  |j
                         |j                  | j                         |S t        j                  d      )a=  Log on to this account.

        Takes care to not start a connection if a connection is
        already in progress.  You will need to implement
        L{_startLogOn} for this to work, and it would be a good idea
        to override L{_loginFailed} too.

        @returntype: Deferred L{interfaces.IClient}
           zConnection in progress)
ro   rn   _startLogOnaddCallback	_cb_logOnregisterAccountClient
addErrback_loginFailedr   ConnectError)r   rN   ds      r   logOnzAbstractAccount.logOn   sx     ""T^^!"D  (AMM$..) MM&667LL**+H$$%=>>r   c                     | j                   j                  |      }|!| j                  ||       }|| j                   |<   |S )zkGroup factory.

        @param name: Name of the group on this account.
        @type name: string
        )rf   get_groupFactory)r   r   groups      r   getGroupzAbstractAccount.getGroup   sB       &=&&tT2E!&DLLr   c                     | j                   j                  |      }|!| j                  ||       }|| j                   |<   |S )zmPerson factory.

        @param name: Name of the person on this account.
        @type name: string
        )rg   r   _personFactory)r   r   persons      r   	getPersonzAbstractAccount.getPerson   sB     ""4(>((t4F"(DMM$r   c                     t               )z{Start the sign on process.

        Factored out of L{logOn}.

        @returntype: Deferred L{interfaces.IClient}
        )NotImplementedError)r   rN   s     r   rx   zAbstractAccount._startLogOn   s     "##r   c                 0    d| _         d| _        || _        |S )Nr   rw   )ro   rn   r    )r   r    s     r   rz   zAbstractAccount._cb_logOn   s    r   c                 "    d| _         d| _        |S )zErrorback for L{logOn}.

        @type reason: Failure

        @returns: I{reason}, for further processing in the callback chain.
        @returntype: Failure
        r   )ro   rn   rX   s     r   r}   zAbstractAccount._loginFailed   s     r   c                 0    d | _         d| _        d| _        |S )Nr   )r    ro   rn   )r   r    rS   s      r   rU   zAbstractAccount._clientLost  s    r   r&   c                     dj                  | j                  | j                  | j                  | j                  | j
                        S )Nz<{}: {} ({}@{}:{})>)formatr+   r1   rb   rd   re   r   s    r   r,   zAbstractAccount.__repr__  s:    $++NNMMIIII
 	
r   )r4   r5   r6   r[   rn   ro   r    r   r   r:   r   persistanceVersionr   rl   rq   ru   r   r   r   rx   rz   r}   rU   r7   r,   r8   r   r   r^   r^   |   sk    2 IMF!M#N	%?.

$

# 
r   r^   N)r[   typingr   twisted.internetr   twisted.internet.protocolr   r   twisted.persistedr   twisted.python.failurer   twisted.python.reflectr
   twisted.words.im.localsr   r   r   r:   rG   rp   r^   r8   r   r   <module>r      sU     " > $ * 2 9
&9 &9R9 960 0DW
f&& W
r   