o b@sdZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZmZGd d d ZGd d d ZGd ddZGddde jZdS)zyInstance Messenger base classes for protocol support. You will find these useful if you're adding a new protocol to IM. )Type)error)ProtocolconnectionDone)styles)FailureprefixedMethods)OFFLINE OfflineErrorc@sPeZdZddZddZddZddZd d Zd efd d Z d efddZ dS) AbstractGroupcCs||_||_dSN)nameaccount)selfrrr>/usr/lib/python3/dist-packages/twisted/words/im/basesupport.py__init__s zAbstractGroup.__init__cC t|dS)zfinds group commands these commands are methods on me that start with imgroup_; they are called with no arguments imgroup_rrrrrgetGroupCommands zAbstractGroup.getGroupCommandscCr)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)rtargetrrrgetTargetCommands#s zAbstractGroup.getTargetCommandscC |jjst|jj|jdSr )rclientr joinGrouprrrrrjoin.zAbstractGroup.joincCrr )rrr leaveGrouprrrrrleave3r zAbstractGroup.leavereturncCsd|jd|jdS)N< >) __class__rrrrr__repr__8szAbstractGroup.__repr__cC|jd|jjSN@rr accountNamerrrr__str__;zAbstractGroup.__str__N) __name__ __module__ __qualname__rrrrr"strr(r.rrrrr s r c@s@eZdZddZddZddZdefdd Zdefd d Zd S) AbstractPersoncCs||_||_t|_dSr )rrr status)rr baseAccountrrrr@s zAbstractPerson.__init__cCr)zfinds person commands these commands are methods on me that start with imperson_; they are called with no arguments imperson_rrrrrgetPersonCommandsErz AbstractPerson.getPersonCommandscCsdS)z# Returns a string. z--rrrrr getIdleTimeMszAbstractPerson.getIdleTimer#cCsd|jd|jd|jdS)Nr$r%/r&)r'rr5rrrrr(SszAbstractPerson.__repr__cCr)r*r,rrrrr.Vr/zAbstractPerson.__str__N) r0r1r2rr8r9r3r(r.rrrrr4?s r4c@sLeZdZUdZdZeeed<ddZddZ e fde fd d Z d d Z dS) AbstractClientMixinzDesigned to be mixed in to a Protocol implementing class. Inherit from me first. @ivar _logonDeferred: Fired when I am done logging in. N _protoBasecCs<|jjD] }t|tr||j_nq ||_||_||_dSr )r' __bases__ issubclassrr<rchat_logonDeferred)rrchatui logonDeferredbaserrrrds   zAbstractClientMixin.__init__cCs|j|dSr )r<connectionMaderrrrrDosz"AbstractClientMixin.connectionMadereasoncCs$|j||||j||Sr )r _clientLostunregisterAsAccountClientr<connectionLostrrErrrrHrsz"AbstractClientMixin.connectionLostcCs|j|dS)z*Tell the chat UI that I have `signed off'.N)r?unregisterAccountClientrrrrrGwsz-AbstractClientMixin.unregisterAsAccountClient)r0r1r2__doc__r<rr__annotations__rrDrrrHrGrrrrr;Zs   r;c@seZdZdZdZdZdZeZe Z dZ ddZ ddZ d d Zd d Zd dZddZddZddZddZddZddZdefddZdS)AbstractAccountaBase class for Accounts. I am the start of an implementation of L{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: rNcCs4||_||_||_||_||_||_i|_i|_dSr )r- autoLoginusernamepasswordhostport_groups_persons)rr-rOrPrQrRrSrrrrs zAbstractAccount.__init__cCs$dD] }t||st||iqdS)N)rTrU)hasattrsetattr)rkrrrupgrateToVersion2s   z!AbstractAccount.upgrateToVersion2c Cs6tj|}dD]}z||=WqtyYqw|S)N)r _isOnline _isConnecting)r Versioned __getstate__KeyError)rstaterXrrrr]s   zAbstractAccount.__getstate__cCs|jSr )rZrrrrisOnlineszAbstractAccount.isOnlinecCsN|js"|js"d|_||}||j||j||j|St 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} zConnection in progress) r[rZ _startLogOn addCallback _cb_logOnregisterAccountClient addErrback _loginFailedr ConnectError)rrAdrrrlogOns      zAbstractAccount.logOncC.|j|}|dur|||}||j|<|S)zkGroup factory. @param name: Name of the group on this account. @type name: string N)rTget _groupFactory)rrgrouprrrgetGroup   zAbstractAccount.getGroupcCrk)zmPerson factory. @param name: Name of the person on this account. @type name: string N)rUrl_personFactory)rrpersonrrr getPersonrpzAbstractAccount.getPersoncCst)z{Start the sign on process. Factored out of L{logOn}. @returntype: Deferred L{interfaces.IClient} )NotImplementedError)rrArrrrbszAbstractAccount._startLogOncCsd|_d|_||_|S)Nrra)r[rZr)rrrrrrdzAbstractAccount._cb_logOncCsd|_d|_|S)zErrorback for L{logOn}. @type reason: Failure @returns: I{reason}, for further processing in the callback chain. @returntype: Failure r)r[rZrIrrrrgszAbstractAccount._loginFailedcCsd|_d|_d|_|S)Nr)rr[rZ)rrrErrrrFruzAbstractAccount._clientLostr#cCsd|j|j|j|j|jS)Nz<{}: {} ({}@{}:{})>)formatr'r-rPrRrSrrrrr( szAbstractAccount.__repr__)r0r1r2rKrZr[rr rmr4rqpersistanceVersionrrYr]r`rjrorsrbrdrgrFr3r(rrrrrM|s(      rMN)rKtypingrtwisted.internetrtwisted.internet.protocolrrtwisted.persistedrtwisted.python.failurertwisted.python.reflectr twisted.words.im.localsr r r r4r;r\rMrrrrs     )"