o
    >h%                     @   s   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
 d
ZG dd dZG dd dZG d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                   @   sP   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdefddZ	defddZ
dS )AbstractGroupc                 C   s   || _ || _d S N)nameaccount)selfr   r    r   |/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/im/basesupport.py__init__   s   
zAbstractGroup.__init__c                 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   r   r   r   getGroupCommands      
zAbstractGroup.getGroupCommandsc                 C   r   )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   targetr   r   r   getTargetCommands#   s   
	zAbstractGroup.getTargetCommandsc                 C       | j jst| j j| j d S r   )r   clientr   	joinGroupr   r   r   r   r   join.      zAbstractGroup.joinc                 C   r   r   )r   r   r   
leaveGroupr   r   r   r   r   leave3   r    zAbstractGroup.leavereturnc                 C   s   d| j  d| jdS )N< >)	__class__r   r   r   r   r   __repr__8   s   zAbstractGroup.__repr__c                 C      | j  d| jj S N@r   r   accountNamer   r   r   r   __str__;      zAbstractGroup.__str__N)__name__
__module____qualname__r   r   r   r   r"   strr(   r.   r   r   r   r   r      s    r   c                   @   s@   e Zd Zdd Zdd Zdd Zdefdd	Zdefd
dZdS )AbstractPersonc                 C   s   || _ || _t| _d S r   )r   r   r
   status)r   r   baseAccountr   r   r   r   @   s   
zAbstractPerson.__init__c                 C   r   )zfinds person commands

        these commands are methods on me that start with imperson_; they are
        called with no arguments
        	imperson_r   r   r   r   r   getPersonCommandsE   r   z AbstractPerson.getPersonCommandsc                 C   s   dS )z#
        Returns a string.
        z--r   r   r   r   r   getIdleTimeM   s   zAbstractPerson.getIdleTimer#   c                 C   s   d| j  d| jd| j dS )Nr$   r%   /r&   )r'   r   r5   r   r   r   r   r(   S   s   zAbstractPerson.__repr__c                 C   r)   r*   r,   r   r   r   r   r.   V   r/   zAbstractPerson.__str__N)	r0   r1   r2   r   r8   r9   r3   r(   r.   r   r   r   r   r4   ?   s    r4   c                   @   sP   e Zd ZU dZdZee ed< dd Zdd Z	e
fded	dfd
dZd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                 C   s<   | j jD ]}t|tr|| j _ nq	 || _|| _|| _d S r   )r'   	__bases__
issubclassr   r<   r   chat_logonDeferred)r   r   chatuilogonDeferredbaser   r   r   r   d   s   

zAbstractClientMixin.__init__c                 C   s   | j |  d S r   )r<   connectionMader   r   r   r   rD   o   s   z"AbstractClientMixin.connectionMadereasonr#   c                 C   s$   | j | | |   | j| |S r   )r   _clientLostunregisterAsAccountClientr<   connectionLostr   rE   r   r   r   rH   r   s   z"AbstractClientMixin.connectionLostc                 C   s   | j |  dS )z*Tell the chat UI that I have `signed off'.N)r?   unregisterAccountClientr   r   r   r   rG   w   s   z-AbstractClientMixin.unregisterAsAccountClient)r0   r1   r2   __doc__r<   r   r   __annotations__r   rD   r   r   rH   rG   r   r   r   r   r;   Z   s   
 r;   c                   @   s   e Zd ZdZdZdZdZeZe	Z
dZdd Zdd Zd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdefd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                 C   s4   || _ || _|| _|| _|| _|| _i | _i | _d S r   )r-   	autoLoginusernamepasswordhostport_groups_persons)r   r-   rO   rP   rQ   rR   rS   r   r   r   r      s   
zAbstractAccount.__init__c                 C   s$   dD ]}t | |st| |i  qd S )N)rT   rU   )hasattrsetattr)r   kr   r   r   upgrateToVersion2   s
   
z!AbstractAccount.upgrateToVersion2c              	   C   s6   t j| }dD ]}z||= W q ty   Y qw |S )N)r   	_isOnline_isConnecting)r   	Versioned__getstate__KeyError)r   staterX   r   r   r   r]      s   
zAbstractAccount.__getstate__c                 C   s   | j S r   )rZ   r   r   r   r   isOnline   s   zAbstractAccount.isOnlinec                 C   sN   | j s"| js"d| _ | |}|| j ||j || j |S t	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)
r[   rZ   _startLogOnaddCallback	_cb_logOnregisterAccountClient
addErrback_loginFailedr   ConnectError)r   rA   dr   r   r   logOn   s   


zAbstractAccount.logOnc                 C   .   | j |}|du r| || }|| j |< |S )zkGroup factory.

        @param name: Name of the group on this account.
        @type name: string
        N)rT   get_groupFactory)r   r   groupr   r   r   getGroup   
   
zAbstractAccount.getGroupc                 C   rk   )zmPerson factory.

        @param name: Name of the person on this account.
        @type name: string
        N)rU   rl   _personFactory)r   r   personr   r   r   	getPerson   rp   zAbstractAccount.getPersonc                 C   s   t  )z{Start the sign on process.

        Factored out of L{logOn}.

        @returntype: Deferred L{interfaces.IClient}
        )NotImplementedError)r   rA   r   r   r   rb      s   zAbstractAccount._startLogOnc                 C   s   d| _ d| _|| _|S )Nr   ra   )r[   rZ   r   )r   r   r   r   r   rd         zAbstractAccount._cb_logOnc                 C   s   d| _ d| _|S )zErrorback for L{logOn}.

        @type reason: Failure

        @returns: I{reason}, for further processing in the callback chain.
        @returntype: Failure
        r   )r[   rZ   rI   r   r   r   rg      s   zAbstractAccount._loginFailedc                 C   s   d | _ d| _d| _|S )Nr   )r   r[   rZ   )r   r   rE   r   r   r   rF     ru   zAbstractAccount._clientLostr#   c                 C   s   d | j| j| j| j| jS )Nz<{}: {} ({}@{}:{})>)formatr'   r-   rP   rR   rS   r   r   r   r   r(     s   zAbstractAccount.__repr__)r0   r1   r2   rK   rZ   r[   r   r   rm   r4   rq   persistanceVersionr   rY   r]   r`   rj   ro   rs   rb   rd   rg   rF   r3   r(   r   r   r   r   rM   |   s(    		rM   N)rK   typingr   twisted.internetr   twisted.internet.protocolr   r   twisted.persistedr   twisted.python.failurer   twisted.python.reflectr	   twisted.words.im.localsr
   r   r   r4   r;   r\   rM   r   r   r   r   <module>   s   )"