U AT^Zc@sFddlZddlZddlZddlmZdgZdZdZe dgZ e dgZ e dgZ e dgZ e d gZe dgZe d gZe d gZe d gZe d gZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZe dgZ e dgZ!e dgZ"e dgZ#e dgZ$e dgZ%e dgZ&e d gZ'e d!gZ(e d"gZ)e d#gZ*e d$gZ+e d%gZ,e d&gZ-e d'gZ.e d(gZ/e d)gZ0e d*gZ1e dgZ2e d+gZ3e d,gZ4e d-gZ5e d.gZ6e d/gZ7e d0gZ8e d1gZ9e d2gZ:e d3gZ;e d4gZe d7gZ?e d8gZ@e d9gZAe d:gZBe d;gZCe dgZFe d?gZGe d@gZHe dAgZIe dBgZJe dCgZKe dDgZLe dEgZMe dFgZNe dGgZOe dgZPe dgZQeRedHrejSZTnejUZTGdIddZVdJdKZWeXdLkrBeWdS)MN) monotonicTelnetiiiiiiiiiiiiiiiiiiiiiiii i i i i iiiiiiiiiiiiiiiiii i!i"i#i$i%i&i'i(i)i*i+i,i-i.i/i0i1iii PollSelectorc@seZdZddejfddZdejfddZddZd d Zd d Z d dZ ddZ ddZ ddZ d;ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4ZdrrrrDszTelnet.sock_availc Cstjdkr|dSt}||tj|tjtj|D]\}}|j |krz | }Wn*t k rt dYW5QRdSX|rtj |dtj qD|j tjkrDtjd}|sW5QRdS||qDqZkeyZeventstextlinerrrinteracts*     zTelnet.interactcCs<ddl}||jdtj}|s&q8||dqdS)NrrrV)_threadZstart_new_threadlistenerrrXr\r/r])rrar_rrrrW3s  zTelnet.mt_interactcCsTz |}Wntk r*tdYdSX|rDtj|dqtjqdS)NrUrV)rFrHr'rrYr/rZr[)rZdatarrrrb=s zTelnet.listenerc CsTd}|dd}tt|}|D]0}t||ds |s>ddl}|||||<q |dk rdt|}t}||tj |j s&| |D]X}|| |j }|r|} |j d| } |j | d|_ ||| fW5QRSq|dk r||} |t}| s|dkrzq&nqz|qzW5QRX|} | sJ|j rJtdd| fS)Nsearchri)Zranger1hasattrreZcompiler3r4r5r6r7rr2rcrr&r8r9r:rH) rZlistr reZindicesr;r=r>ZmZer^ZreadyrrrexpectJsB      z Telnet.expectcCs|Sr rr#rrr __enter__zTelnet.__enter__cCrr r!)rZtypeZvalueZ tracebackrrr__exit__rhzTelnet.__exit__r r )!__name__Z __module__Z __qualname__rZ_GLOBAL_DEFAULT_TIMEOUTrrr$r(r*r"r+r,r/r?rBrCrErFrGr:rIrJr2rOr9rDr`rWrbrfrgrirrrrrs<7   %    H  8c Csd}tjddr2tjddkr2|d}tjd=qd}tjddrNtjd}d}tjddrtjd}z t|}Wn tk rt|d}YnXt(}|||j||dd| W5QRXdS) Nrrz-dZ localhostrZtcpg?)r ) rZargvZintZ ValueErrorrZ getservbynamerr*rr`)rr r ZportstrZtnrrrtests$     rkZ__main__)Yrrr6Ztimerr3Z__all__rrZbytesr-rLrKrNrMrPrRZNOPZDMZBRKZIPZAOZAYTZECZELZGArQZBINARYZECHOZRCPZSGAZNAMSZSTATUSZTMZRCTEZNAOLZNAOPZNAOCRDZNAOHTSZNAOHTDZNAOFFDZNAOVTSZNAOVTDZNAOLFDZXASCIIZLOGOUTZBMZDETZSUPDUPZ SUPDUPOUTPUTZSNDLOCZTTYPEZEORZTUIDZOUTMRKZTTYLOCZ VT3270REGIMEZX3PADZNAWSZTSPEEDZLFLOWZLINEMODEZXDISPLOCZ OLD_ENVIRONZAUTHENTICATIONZENCRYPTZ NEW_ENVIRONZTN3270EZXAUTHZCHARSETZRSPZCOM_PORT_OPTIONZSUPPRESS_LOCAL_ECHOZTLSZKERMITZSEND_URLZ FORWARD_XZ PRAGMA_LOGONZ SSPI_LOGONZPRAGMA_HEARTBEATZEXOPLrSrdrr4ZSelectSelectorrrkrjrrrrZ$s