ó Afc@söddlZddlZddlZddlZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZi dd6dd6dd6dd6dd 6dd 6dd 6dd 6dd 6dd6dd6dd6ZdZdZd„Zd „Zd!„Zd"„Zd#„Zd$„Zd%„Zd&„Zd'„Zd(„Zd)„Z d*„Z!d+„Z"d,„Z#i ed6ed6e"d 6e"d 6ed 6e d 6e!d 6e"d6e#d6Z$d-d3d.„ƒYZ%d/d4d0„ƒYZ&d1„Z'd2„Z(e(ƒdS(5i’’’’Ntsgopher.micro.umn.eduiFt0t1t2t3t4t5t6t7t8t9t+tssssssss ssss ss s cCsh|st}n*t|ƒtdƒkr9tj|ƒ}ntjtjtjƒ}|j||fƒ|S(NR(tDEF_PORTttypetstringtatoitsockettAF_INETt SOCK_STREAMtconnect(thosttportR ((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt open_socket)s cCs:t||ƒ}|j|tƒ|jdƒ|jdƒS(Nitr(RtsendtCRLFtshutdowntmakefile(tselectorRRR ((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt send_request3s cCs)t|||ƒ}g}x|jƒ}|s6dGHPn|dtkrS|d }n|dtkrp|d }n|dkr€Pn|s‘dGHqn|d}tj|dtƒ}t|ƒdkrÕd |fGHqnt|ƒdkrśd |dfGHn|jd|ƒ|j|ƒqW|j ƒ|S( Ns(Unexpected EOF from server)iž’’’i’’’’t.s(Empty line from server)iiis(Bad line from server: %r)s(Extra info from server: %r)( RtreadlineRRt splitfieldstTABtlentinserttappendtclose(RRRtftlisttlinettypechartparts((s+/usr/lib64/python2.7/Demo/sockets/gopher.pytget_menu:s6       cCs g}t||||jƒ|S(N(tget_alt_textfileR%(RRRR(((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt get_textfileXscCs³t|||ƒ}x|jƒ}|s0dGHPn|dtkrM|d }n|dtkrj|d }n|dkrzPn|d dkr—|d}n||ƒqW|jƒdS(Ns(Unexpected EOF from server)iž’’’i’’’’Ris..i(RR RR&(RRRtfuncR'R)((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR-^s      cCs,t|||ƒ}|jƒ}|jƒ|S(N(RtreadR&(RRRR'tdata((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt get_binaryqs  cCs@t|||ƒ}x'|j|ƒ}|s.Pn||ƒqWdS(N(RR0(RRRR/t blocksizeR'R1((s+/usr/lib64/python2.7/Demo/sockets/gopher.pytget_alt_binaryxs cGsūt}t}t}t|ƒ}|dkrA|drA|d}n|dkrd|drd|d}n|dkr‡|dr‡|d}n|dkrŸtd‚nyt|||ƒWnAtjk rį}dG|GHtj dƒnt k rödGHnXdS(Niiiis too many argss Socket error:s [Goodbye]( t DEF_SELECTORtDEF_HOSTR R#t RuntimeErrort browse_menuRterrortsystexittKeyboardInterrupt(targsRRRtntmsg((s+/usr/lib64/python2.7/Demo/sockets/gopher.pytbrowserƒs&        cCsžt|||ƒ}xådGHdGt|ƒGHdG|GdG|GHHx‰tt|ƒƒD]u}||}|d|d}}tjt|dƒdƒdG|Gtj|ƒr°t|GHqNd t|ƒd GHqNWHx”ytd ƒ}Wnt k ršHdSX|sūdSytj |ƒ} Wntj k r,d GHqĖnXd| koJt|ƒknsZd GHqĖnPqĖW|| d}|d}|dd!\} } } t j|ƒrńt |} y| | | | ƒWqöt tjfk rķdGtjGdGtjGHqöXqdGHqWdS(Ns----- MENU -----s Selector:sHost:s Port:iiit:ssChoice [CR == up a level]: s#Choice must be a number; try again:sChoice out of range; try again:iis***sUnsupported object type(R,treprtrangeR#Rtrjustttypenamethas_keyt raw_inputtEOFErrorRt atoi_errort typebrowsertIOErrorRR9R:texc_typet exc_value(RRRR(tititemR*t descriptiontstrtchoicet i_selectorti_hostti_portt browserfunc((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR8™sR "  "  cCsŪd}y8tjddƒ}t|ƒ}t||||jƒWntk r\}dG|GHnX|rp|jƒntƒ}|sƒdSt|ƒ}yt||||jƒdGHWntk rĢ}dG|GHnX|jƒdS(Ns ${PAGER-more}twsIOError:sDone.( tNonetostpopent SaveLinesR-twritelnRLR&t open_savefile(RRRtxtpR?R'((s+/usr/lib64/python2.7/Demo/sockets/gopher.pytbrowse_textfileĒs&       cCsŸx˜dGHdGt|ƒGHdG|GdG|GHHytdƒ}Wntk rNHPnXtj|ƒ}|shPnd|krdGHqnt|t|||ƒqWdS(Ns----- SEARCH -----s Selector:sHost:s Port:sQuery [CR == up a level]: s s"Sorry, queries cannot contain tabs(RCRHRIRtstripR8R"(RRRtquery((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt browse_searchŻs"  cCsp|rdGt|ƒGHnt|ƒtdƒkr?t|ƒ}ntjd|d|ƒ}|rldG|GHndS(Ns Log in asRsset -x; exec telnet t s Exit status:(RCRRZtsystem(RRRtsts((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt browse_telnetńscCsFtƒ}|sdSt|ƒ}t||||jdƒ|jƒdS(Niii (R^tSaveWithProgressR4twriteR&(RRRR'R_((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt browse_binaryūs   cCst|||ƒdS(N(Rk(RRR((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt browse_soundsR\cBs#eZd„Zd„Zd„ZRS(cCs ||_dS(N(R'(tselfR'((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyt__init__scCs|jj|dƒdS(Ns (R'Rj(RmR)((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR]scCs%|jjƒ}|r!dG|GHndS(Ns Exit status:(R'R&(RmRg((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR&s(t__name__t __module__RnR]R&(((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR\s  RicBs#eZd„Zd„Zd„ZRS(cCs ||_dS(N(R'(RmR'((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyRnscCs1tjjdƒtjjƒ|jj|ƒdS(Nt#(R:tstdoutRjtflushR'(RmR1((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyRjs cCs&H|jjƒ}|r"dG|GHndS(Ns Exit status:(R'R&(RmRg((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR& s(RoRpRnRjR&(((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyRis  cCs2ytdƒ}Wntk r%HdSXtj|ƒ}|s?dS|ddkr¹tj|dƒ}ytj|dƒ}Wn'tk r”}t|ƒGdG|GHdSXdGt|ƒGdGH|S|dd krŽtj j |ƒ}nyt |dƒ}Wn'tk r}t|ƒGdG|GHdSXd Gt|ƒGdGH|S( Ns<Save as file [CR == don't save; |pipeline or ~user/... OK]: it|iRXRAsPiping throughs...t~s Saving to( RHRIRYRRbRZR[RLRCtpatht expandusertopen(tsavefiletcmdR`R?R'((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyR^'s6  cCs tjdr"dGHtjdƒnätjdrWttjdtjdtjdƒnÆtjdrŪy-tjtjdƒ}d}tjd}Wn4tjk rĒtjd}tjd}d}nXt|||ƒn+tjdr’tdtjdƒntƒdS(Nis(usage: gopher [ [selector] host [port] ]iiiR(R:targvR;R@RRRJ(RRR((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyttestEs$  (     ((()RR:RZRR5R6R t T_TEXTFILEtT_MENUtT_CSOtT_ERRORtT_BINHEXtT_DOSt T_UUENCODEtT_SEARCHtT_TELNETtT_BINARYt T_REDUNDANTtT_SOUNDRFRR"RRR,R.R-R2R4R@R8RaRdRhRkRlRKR\RiR^R|(((s+/usr/lib64/python2.7/Demo/sockets/gopher.pyts\           .