
    Vh%                        d 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 ddlmZmZmZ  G d	 d
ej&                        Z eej*                         G d dej,                               Z G d dej0                  ej2                        ZeddZ eej8                         G d dej:                               Zy)z2
L{twisted.words} support for Instance Messenger.
    )implementer)defererror)log)Failure)pb)basesupport
interfaces)AWAYOFFLINEONLINEc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TwistedWordsPersonzHI a facade for a person you can talk to through a twisted.words service.c                 \    t         j                  j                  | ||       t        | _        y N)r	   AbstractPerson__init__r   status)selfnamewordsAccounts      J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/im/pbsupport.pyr   zTwistedWordsPerson.__init__   s!    ""++D$E    c                 R    | j                   t        k(  xs | j                   t        k(  S r   )r   r   r   r   s    r   isOnlinezTwistedWordsPerson.isOnline   s    v%?4;;$+>?r   c                     | j                   S r   )r   r   s    r   	getStatuszTwistedWordsPerson.getStatus   s    {{r   c                 4   |r\| j                   j                  j                  j                  | j                  ||      }|j                  | j                  d|z          |S | j                   j                  j                  j                  d| j                  |      S )zReturn a deferred...* directMessage)accountclientperspectiver!   r   
addErrbackmetadataFailed
callRemoter   textmetadatads       r   sendMessagezTwistedWordsPerson.sendMessage!   sx    ##//==diixXALL,,dTk:H<<&&22==D r   c                     t        d|d|       | j                  j                  j                  j	                  | j
                  |      S )Nresult:text:)printr"   r#   r$   r!   r   r   resultr)   s      r   r&   z!TwistedWordsPerson.metadataFailed,   s7    i$/||""..<<TYYMMr   c                 d    || _         | j                  j                         j                  |        y r   )r   chatgetContactsListsetContactStatus)r   r   s     r   	setStatuszTwistedWordsPerson.setStatus0   s$    		!!#44T:r   N)
__name__
__module____qualname____doc__r   r   r   r,   r&   r7    r   r   r   r      s%    R@	N;r   r   c                   8    e Zd Zd Zd	dZd Zd Zd Zd Zd Z	y)
TwistedWordsGroupc                 T    t         j                  j                  | ||       d| _        y Nr   )r	   AbstractGroupr   joined)r   r   wordsClients      r   r   zTwistedWordsGroup.__init__7   s!    !!**4{Cr   Nc                 6   |r]| j                   j                  j                  j                  d| j                  ||      }|j                  | j                  d|z          |S | j                   j                  j                  j                  d| j                  |      S )zReturn a deferred.groupMessager    )r"   r#   r$   r'   r   r%   r&   r(   s       r   sendGroupMessagez"TwistedWordsGroup.sendGroupMessage;   s     ##//::		4A LL,,dTk:H<<&&22==		4 r   c                     | j                   j                  j                  j                  d|| j                  j                  d| j                         y )NsetGroupMetadata)topictopic_authorr"   r#   r$   r'   r   )r   r)   s     r   setTopiczTwistedWordsGroup.setTopicI   s<    ''22DKK,<,<=II	
r   c                     t        d|d|       | j                  j                  j                  j	                  d| j
                  |      S )Nr.   r/   rE   )r0   r"   r#   r$   r'   r   r1   s      r   r&   z TwistedWordsGroup.metadataFailedP   s>    i$/||""..99DIIt
 	
r   c                     d| _         y )N   rB   r   s    r   joiningzTwistedWordsGroup.joiningV   	    r   c                     d| _         y r@   rP   r   s    r   leavingzTwistedWordsGroup.leavingY   rR   r   c                 v    | j                   j                  j                  j                  d| j                        S N
leaveGrouprK   r   s    r   leavezTwistedWordsGroup.leave\   s)    ||""..99,		RRr   r   )
r8   r9   r:   r   rF   rL   r&   rQ   rT   rX   r<   r   r   r>   r>   5   s&    

Sr   r>   c                       e Zd ZdZddZd Zd Zd Zd Zd Z	dd	Z
d
 Zd Zd ZddZd Zd Zd Zd Zd Zd Zd Zy)TwistedWordsClientzIn some cases, this acts as an Account, since it a source of text
    messages (multiple Words instances may be on a single PB connection)
    Nc                     dj                  |j                  ||      | _        || _        t        d||       || _        || _        || _        y )Nz
{} ({}:{})zHELLO I AM A PB SERVICE)formataccountNamer   r0   r4   r"   _logonDeferred)r   acctserviceNameperspectiveNamechatuir^   s         r   r   zTwistedWordsClient.__init__e   sP    '..

 $	'oF	,r   c                 :    | j                   j                  ||       S r   )r4   	getPersonr   r   s     r   rd   zTwistedWordsClient.getPersonq   s    yy""4..r   c                 :    | j                   j                  ||       S r   )r4   getGroupre   s     r   rg   zTwistedWordsClient.getGroupt   s    yy!!$--r   c                 V    | j                   j                  | j                  |            S r   )r4   getGroupConversationrg   re   s     r   ri   z'TwistedWordsClient.getGroupConversationw   s     yy--dmmD.ABBr   c                 <    | j                   j                  d|       y )N
addContact)r$   r'   re   s     r   rk   zTwistedWordsClient.addContactz   s    ##L$7r   c                 ^    t        d||       | j                  |      j                  |       y )Nzreceived group members:)r0   ri   setGroupMembers)r   namesgroups      r   remote_receiveGroupMembersz-TwistedWordsClient.remote_receiveGroupMembers}   s(    '6!!%(88?r   c                 f    t        d||||       | j                  |      j                  |||       y )Nzreceived a group message)r0   ri   showGroupMessage)r   senderro   messager*   s        r   remote_receiveGroupMessagez-TwistedWordsClient.remote_receiveGroupMessage   s0    (&%(K!!%(99&'8Tr   c                 ^    t        d||       | j                  |      j                  |       y )Nzmember joined)r0   ri   memberJoinedr   memberro   s      r   remote_memberJoinedz&TwistedWordsClient.remote_memberJoined   s'    ovu-!!%(55f=r   c                 Z    t        d       | j                  |      j                  |       y )Nzmember left)r0   ri   
memberLeftrx   s      r   remote_memberLeftz$TwistedWordsClient.remote_memberLeft   s#    m!!%(33F;r   c                 Z    | j                   j                  ||       j                  |       y r   r4   rd   r7   )r   r   r   s      r   remote_notifyStatusChangedz-TwistedWordsClient.remote_notifyStatusChanged   s!    		D$'11&9r   c                     | j                   j                  | j                   j                  ||             j                  ||       y r   )r4   getConversationrd   showMessage)r   r   rt   r*   s       r   remote_receiveDirectMessagez.TwistedWordsClient.remote_receiveDirectMessage   s5    		!!$))"5"5dD"ABNNX	
r   c                 n    |D ]0  \  }}| j                   j                  ||       j                  |       2 y r   r   )r   clistr   r   s       r   remote_receiveContactListz,TwistedWordsClient.remote_receiveContactList   s4    ! 	>LD&IId+55f=	>r   c                 v    d|v r5| j                  |      j                  |d   |j                  dd              y y )NrI   rJ   )ri   rL   get)r   dict_	groupNames      r   remote_setGroupMetadataz*TwistedWordsClient.remote_setGroupMetadata   s<    e%%i099g		.$ ? r   c                     | j                  |      j                          | j                  j                  d|      j	                  | j
                  |      S )N	joinGroup)rg   rQ   r$   r'   addCallback_cbGroupJoinedre   s     r   r   zTwistedWordsClient.joinGroup   sH    d##%**;=II
 	
r   c                     | j                  |      j                          | j                  j                  d|      j	                  | j
                  |      S rV   )rg   rT   r$   r'   r   _cbGroupLeftre   s     r   rW   zTwistedWordsClient.leaveGroup   sH    d##%**<>JJt
 	
r   c                     | j                   j                  | j                  |            }|j                  dd       | j                  j                  d|       y )Nsysz
you joinedgetGroupMembers)r4   ri   rg   rr   r$   r'   r   r2   r   	groupConvs       r   r   z!TwistedWordsClient._cbGroupJoined   sF    II224==3FG	""5,7##$5t<r   c                     t        d|       | j                  j                  | j                  |      d      }|j	                  dd       y )NleftrO   r   zyou left)r0   r4   ri   rg   rr   r   s       r   r   zTwistedWordsClient._cbGroupLeft   s;    fdII224==3FJ	""5*5r   c                     t        d|       | j                  | j                  j                  |        || _        | j                  j                          y )NzConnected Words Client!)r0   r^   callbackr$   r4   r5   )r   r$   s     r   	connectedzTwistedWordsClient.connected   sE    '5*((.&		!!#r   r   )r8   r9   r:   r;   r   rd   rg   ri   rk   rp   ru   rz   r}   r   r   r   r   r   rW   r   r   r   r<   r   r   rZ   rZ   `   sd    
-/.C8@U><:

>

=
6
$r   rZ   N)twisted.wordsztwisted.realityc                   F    e Zd ZdZeZeZ	 d
dZd Z	d Z
d Zd Zd Zd	 Zy)	PBAccountPBNc           	          t         j                  j                  | ||||||       g | _        |sdd|fg}|D ]+  \  }}	}
| j                  j	                  t
        |   |	|
g       - y)z_
        @param username: The name of your PB Identity.
        @type username: string
        r   N)r	   AbstractAccountr   servicesappendpbFrontEnds)r   r]   	autoLoginusernamepasswordhostportr   serviceTyper`   ra   s              r   r   zPBAccount.__init__   sy     	##,,+y(HdD	
 (/8DEH9A 	5KoMM  [);H	r   c                       j                   sX j                  sLd _          j                        }|j                   j                          fd}|j                  |       |S t        j                  d      )z
        @returns: this breaks with L{interfaces.IAccount}
        @returntype: DeferredList of L{interfaces.IClient}s
        rO   c                     | D ]?  \  }}|r#j                  |       j                  |       +t        j                  |       A y r   )registerAccountClient	_cb_logOnr   err)resultssuccessr2   rb   r   s      r   registerManyz%PBAccount.logOn.<locals>.registerMany   s>    '. (OGV44V<v.(r   zConnection in progress)_isConnecting	_isOnline_startLogOnr%   _loginFailedr   r   ConnectionError)r   rb   r+   r   s   ``  r   logOnzPBAccount.logOn   sh     ""T^^!"D  (ALL**+( MM,'H''(@AAr   c                      y r   r<   r   s    r   logOffzPBAccount.logOff   s    r   c                     t        dd       t        j                  | j                  | j                        }|j                  | j                  | j                  |f       |S )NzConnecting... endcallbackArgs)r0   r   getObjectAtr   r   addCallbacks_cbConnected_ebConnected)r   rb   r+   s      r   r   zPBAccount._startLogOn   sI    o3'NN499dii0	t(($*;*;6)Tr   c                     t        d       t        dd       t        j                  || j                  | j                        }|j                  | j                  | j                  |f       |S )Nz
Connected!zIdentifying...r   r   r   )r0   r   authIdentityr   r   r   _cbIdentr   )r   rootrb   r+   s       r   r   zPBAccount._cbConnected   sR    lC(OOD$--?	t}}d&7&7viPr   c                    |s.t        d       | j                  t        t        d                  S t        d       g }| j                  D ]d  \  }}}t        j                         }|j                  |        || ||||      }|j                  d|||      j                  |j                         f t        j                  |      S )Nzfalsely identified.zusername or password incorrectzIdentified!attach)r0   r   r   	Exceptionr   r   Deferredr   r'   r   r   DeferredList)	r   identrb   dlhandlerClasssnamepnamer+   handlers	            r   r   zPBAccount._cbIdent  s    '($$	"BCD  	m*.-- 	&L% AIIaL"4vqAGXueW=II!!		 !!"%%r   c                     t        d       |S )NzNot connected.)r0   )r   r   s     r   r   zPBAccount._ebConnected  s    r   r   )r8   r9   r:   gatewayTyper>   _groupFactoryr   _personFactoryr   r   r   r   r   r   r   r<   r   r   r   r      s<    K%M'N PT$B4&"r   r   )r;   zope.interfacer   twisted.internetr   r   twisted.pythonr   twisted.python.failurer   twisted.spreadr   twisted.words.imr	   r
   twisted.words.im.localsr   r   r   r   r   IGrouprA   r>   ReferenceableAbstractClientMixinrZ   r   IAccountr   r   r<   r   r   <module>r      s   

 ' )  *  4 9 9;33 ;B Z'S11 'S  'STZ$));+J+J Z$z !3tL Z  !U++ U "Ur   