
    Yf%                         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dS )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                   D    e Zd Zd Zd Zd Zd Zd ZdefdZ	defdZ
d	S )
AbstractGroupc                 "    || _         || _        d S N)nameaccount)selfr   r   s      N/var/www/html/env/lib/python3.11/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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11r   c                 t    | j         j        st          | j         j                            | j                   d S r   )r   clientr   	joinGroupr   r   s    r   joinzAbstractGroup.join.   s6    |" 	%%di00000r   c                 t    | j         j        st          | j         j                            | j                   d S r   )r   r    r   
leaveGroupr   r   s    r   leavezAbstractGroup.leave3   s6    |" 	&&ty11111r   returnc                 (    d| j          d| j        dS )N< >)	__class__r   r   s    r   __repr__zAbstractGroup.__repr__8   s    24>22DI2222r   c                 .    | j          d| j        j         S N@r   r   accountNamer   s    r   __str__zAbstractGroup.__str__;       )88dl6888r   N)__name__
__module____qualname__r   r   r   r"   r%   strr,   r2    r   r   r   r      s          1 1 1	2 	2 	21 1 1
2 2 2
3# 3 3 3 39 9 9 9 9 9 9r   r   c                   8    e Zd Zd Zd Zd ZdefdZdefdZdS )AbstractPersonc                 :    || _         || _        t          | _        d S 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11r   c                     dS )z#
        Returns a string.
        z--r8   r   s    r   getIdleTimezAbstractPerson.getIdleTimeM   s	     tr   r&   c                 8    d| j          d| j        d| j         dS )Nr(   r)   /r*   )r+   r   r<   r   s    r   r,   zAbstractPerson.__repr__S   s)    @4>@@DI@@$+@@@@r   c                 .    | 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 2 2  A# A A A A9 9 9 9 9 9 9r   r:   c                   T    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dS )
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                    r|| j         _         n&	 || _        || _        || _        d S r   )r+   	__bases__
issubclassr   rH   r   chat_logonDeferred)r   r   chatuilogonDeferredbases        r   r   zAbstractClientMixin.__init__d   s]    N, 	 	D$)) ,0) 	+r   c                 :    | j                             |            d S r   )rH   connectionMader   s    r   rR   z"AbstractClientMixin.connectionMadeo   s    &&t,,,,,r   reasonr&   c                     | j                             | |           |                                  | j                            | |          S r   )r   _clientLostunregisterAsAccountClientrH   connectionLostr   rS   s     r   rW   z"AbstractClientMixin.connectionLostr   sD      v...&&(((--dF;;;r   c                 :    | j                             |            dS )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 <$ < < < <
0 0 0 0 0r   rG   c                   x    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dS )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                 v    || _         || _        || _        || _        || _        || _        i | _        i | _        d S 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                 R    dD ]#}t          | |          st          | |i            $d S )N)rf   rg   )hasattrsetattr)r   ks     r   upgrateToVersion2z!AbstractAccount.upgrateToVersion2   s@    ( 	% 	%A4## %a$$$	% 	%r   c                 v    t           j                            |           }dD ]}	 ||= # t          $ r Y w xY w|S )N)r    	_isOnline_isConnecting)r   	Versioned__getstate__KeyError)r   staterk   s      r   rq   zAbstractAccount.__getstate__   sZ     --d339 	 	A!HH   s   )
66c                     | j         S r   )rn   r   s    r   isOnlinezAbstractAccount.isOnline   s
    ~r   c                    | j         ss| j        sld| _         |                     |          }|                    | 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   s     " 	?T^ 	?!"D  ((AMM$.))) MM&6777LL*+++H$%=>>>r   c                 ~    | 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   sD       &&=&&tT22E!&DLr   c                 ~    | 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   sD     ""4((>((t44F"(DM$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                 f    d                     | j        | j        | j        | j        | j                  S )Nz<{}: {} ({}@{}:{})>)formatr+   r1   rb   rd   re   r   s    r   r,   zAbstractAccount.__repr__  s4    $++NMII
 
 	
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^   |   s         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      sV          " " " " " " > > > > > > > > $ $ $ $ $ $ * * * * * * 2 2 2 2 2 2 9 9 9 9 9 9 9 9
&9 &9 &9 &9 &9 &9 &9 &9R9 9 9 9 9 9 9 960 0 0 0 0 0 0 0DW
 W
 W
 W
 W
f& W
 W
 W
 W
 W
r   