Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/protocols/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyc


[XMc@sKdZddlZejdeddyddlmZWn!ek
r_ddlmZnXddlmZddl	m
Z
ed	Zed
Z
edZedZed
ZedZedZedZedZedZedZedZedZedZedZedZedZedZedZedZedZ edZ!edZ"ed Z#ed!Z$ed"Z%ed#Z&ed$Z'ed%Z(ed&Z)ed'Z*ed(Z+id)e$6d*e%6d+e"6d,e#6d-e6Z,d.Z-d/e
j.fd0YZ/dS(1s<TELNET implementation, with line-oriented command handling.
iNstAs of Twisted 2.1, twisted.protocols.telnet is deprecated.  See twisted.conch.telnet for the current, supported API.t
stackleveli(tStringIO(t	copyright(tprotocolis[1ms[mii
i
iii	iiiiiiiiiiiiiiiiiiiii"iitDOtDONTtWILLtWONTtIPcCs3x,|jD]\}}|j||}q
W|S(N(titemstreplace(tsttdcttktv((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytmultireplacestTelnetcBseZdZdZdZdZdZdZddgZ	dZ
dZdZdZ
d	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZRS(suI am a Protocol for handling Telnet connections. I have two
    sets of special methods, telnet_* and iac_*.

    telnet_* methods get called on every line sent to me. The method
    to call is decided by the current mode. The initial mode is 'User';
    this means that telnet_User is the first telnet_* method to be called.
    All telnet_* methods should return a string which specifies the mode
    to go into next; thus dictating which telnet_* method to call next.
    For example, the default telnet_User method returns 'Password' to go
    into Password mode, and the default telnet_Password method returns
    'Command' to go into Command mode.

    The iac_* methods are less-used; they are called when an IAC telnet
    byte is received. You can define iac_DO, iac_DONT, iac_WILL, iac_WONT,
    and iac_IP methods to do what you want when one of these bytes is
    received.its
s
tUsercCs|jj|dS(s&Send the given data over my transport.N(t	transporttwrite(tselftdata((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyRscCs!|j|j|jdS(s<I will write a welcomeMessage and loginPrompt to the client.N(RtwelcomeMessagetloginPrompt(R((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytconnectionMadescCs-|jj}d|jd|jdtjS(sUOverride me to return a string which will be sent to the client
        before login.s
t.s
Twisted %s
(tfactoryt	__class__t
__module__t__name__Rtversion(Rtx((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyRscCsdS(s-Override me to return a 'login:'-type prompt.s
username: ((R((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyRscCsdS(N((Rtchunk((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt
iacSBchunkscCsdS(N((Rtfeature((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytiac_DOscCsdS(N((RR#((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytiac_DONTscCsdS(N((RR#((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytiac_WILLscCsdS(N((RR#((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytiac_WONTscCsdS(N((RR#((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytiac_IPscCs8t|d|j|}|dk	r4||_ndS(sI call a method that looks like 'telnet_*' where '*' is filled
        in by the current mode. telnet_* methods should return a string which
        will become the new mode.  If None is returned, the mode will not change.
        ttelnet_N(tgetattrtmodetNone(RtlineR+((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytprocessLinescCs&||_|jtttddS(sI take a username, set it to the 'self.username' attribute,
        print out a password prompt, and switch to 'Password' mode. If
        you want to do something else when the username is received (ie,
        create a new user if the user doesn't exist), override me.s
password: tPassword(tusernameRtIACRtECHO(Rtuser((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyttelnet_Users	cCsU|jtttdy|j|j|}WndSX|sGdS|jdS(sI accept a password as an argument, and check it with the
        checkUserAndPass method. If the login is successful, I call
        loggedIn().s*****
tDonetCommand(RR1RR2tcheckUserAndPassR0tloggedIn(Rtpaswdtchecked((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyttelnet_Passwords
cCsdS(sPThe default 'command processing' mode. You probably want to
        override me.R6((Rtcmd((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyttelnet_CommandscCs|j||_x3|jD](}|jj|}|dkrPqqWx|dkr|j| |j|d}|_|j||jdkr|jjnx3|jD](}|jj|}|dkrPqqWqIWdS(sI take a chunk of data and delegate out to telnet_* methods
        by way of processLine. If the current mode is 'Done', I'll close
        the connection. iiR5N(tbuffert
delimiterstfindR.R+RtloseConnection(RR!tdelimtidxtbuf((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytprocessChunks"
cCsat}x#|D]}|jr|jr|jtkr~|tkrn|j|jt}|`|`q|j|qy"t|dt	|j|Wnt
k
rnX|`|`q+||_q|tkr|j}|r|j|}|r|St}nd|_q|j|qW|j}|r]|j|}|r]|SndS(Nsiac_%si(
RtgotIACtiacBytetSBtSER"tgetvalueRR*tiacBytestKeyErrorR1RE(RRR!tchartctwhy((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pytdataReceiveds@	
				"
	cCsdS(s^Called after the user succesfully logged in.
        
        Override in subclasses.
        N((R((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyR8@sN(RRt__doc__RFR,RGtlastLineR>techoR?R+RRRRR"R$R%R&R'R(R.R4R;R=RERPR8(((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyRs2																		0(0RQtwarningstwarntDeprecationWarningt	cStringIORtImportErrorttwistedRttwisted.internetRtchrtESCtBOLD_MODE_ONt
BOLD_MODE_OFFtNULLtLFtCRtBELtBStHTtVTtFFRItNOPtDMtBRKRtAOtAYTtECtELtGARHRRRRR1R2tSUPGAtLINEMODEtHIDEtNOECHORKRtProtocolR(((s</usr/lib/python2.7/dist-packages/twisted/protocols/telnet.pyt<module>sf