^Ic@s6dZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddk Z ddk Z ddk Z ddk Te i Z e iZdZdZdefdYZdefd YZd efd YZd efd YZdefdYZdedZdefdYZdefdYZdefdYZdefdYZdefdYZdefdYZ de!fdYZ"d e!fd!YZ#d"e$fd#YZ%d$efd%YZ&d&Z'd'Z(d(Z)dS()s)networked spam-signature detection clientiN(t*s6$Id: client.py,v 1.48 2003-02-01 10:29:42 ftobin Exp $s /dev/randomtClientcBseZdddgZdZdZdZdZdZdZd Z d Z d Z d Z d Z dddZdZRS(tsockettoutputtaccountsii cCs6titit||_t|_|idS(N(tsignaltSIGALRMthandle_timeoutRtOutputRt build_socket(tselfR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt__init__s  cCs,t}|i|||i|iS(N(t PingRequesttsendt read_responset get_thread(R taddresstmsg((s0/usr/lib/python2.6/site-packages/pyzor/client.pytping$s cCs/t|}|i|||i|iS(N(t InfoRequestR RR(R tdigestRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pytinfo)s cCs2t||}|i|||i|iS(N(t ReportRequestR RR(R RtspecRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pytreport.scCs2t||}|i|||i|iS(N(tWhitelistRequestR RR(R RRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt whitelist3scCs/t|}|i|||i|iS(N(t CheckRequestR RR(R RRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pytcheck8s cCstititi|_dS(N(RtAF_INETt SOCK_DGRAM(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR =scCso|i|i|}tti|i|ii|}|ii dt ||i i |d|dS(Ns sending: %si( tinit_for_sendingRtstrt MacEnvelopetwraptusernametkeystufftkeyRtdebugtreprRtsendto(R RRtaccountt mac_msg_str((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR @s    cCs|i|ii|ifS(N(t time_callRtrecvfromtmax_packet_size(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pytrecvJscCsP|djo h}nti|izt|||SWdtidXdS(Ni(tNoneRtalarmttimeouttapply(R tcalltvarargstkwargs((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR+Ns  cCs|i\}}|iidt|tti|}|iy_|i}||joB|i ot d||fq|ii d||fnWn#t j o|ii dnX|S(Ns received: %ss.received unexpected thread id %d (expected %d)s)received error thread id %d (expected %d)sno thread id received( R.RR&R'tResponset cStringIOtStringIOtensure_completeRt in_ok_ranget ProtocolErrortwarntKeyError(R t expect_idtpacketRRt thread_id((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRVs      (N(t__name__t __module__t __slots__R1R-R RRRRRR R R.R/R+R(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs        t ServerListcBseZdZdZRS(s9http://pyzor.sourceforge.net/cgi-bin/inform-servers-0-3-xcCsoxh|D]`}|}|i}|oA|id o0tid|o|itii|qqWdS(Nt#s[a-zA-Z0-9.-]+:[0-9]+(tstript startswithtretmatchtappendtpyzortAddresstfrom_str(R t serverfiletlinet orig_line((s0/usr/lib/python2.6/site-packages/pyzor/client.pytreadqs (RARBt inform_urlRQ(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRDnstExecCallcBseZdddgZeddgZdZddZdZd Z d Z d Z d Z d Z dZdZdZdZeeZdZeeZh e d6e d6ed6ed6e d6e d6ed6ed6dd6ZRS(tclienttserversRiii<cCsd}d}d}y/titidddddg\}}Wn tij o|inXt|djo|ind}xt|D]l\}}|djo d}q|djo|iq|d jo |}q|d jo d}qqWtd ||_t i |}|o>t |d dt_ ti i dttidnt i|} | idhdd6tid6dd6ttid6} x-| iD]\} }| id| |qW| itii|d| idd} | iddt_tii|pti |n|d} tii|  p | djo=ti i d| i!ddt"| i!dd| n|i#| |_$t|i$p.ti i dti%| ti&dnt|i'| idd|_(|i)i*| p|in|i)| }|dj oby+t+|||fpti&dnWqt,j o$ti i dti&dqXndS(Niisdh:shomedir=tlogthelps-ds-hs--helps --homedirs--logR&s /pyzor.logtas pyzor[s]: RTRUt ServersFiletDiscoverServersURLRt AccountsFiletTimeouttconfigtdiscoversdownloading servers from %s sno valid servers found stimeout from server (s-hs--help(-R/tgetopttsystargvt GetoptErrortusagetlenRRRKt get_homedirtopentstderrtwriteR'tostgetpidtConfigt add_sectionRDRRR RR1titemstsetRQtpathtjoint get_filenametgetinttexiststmkdirtgettdownloadt get_serversRUtremovetexitt get_accountsRTt dispatchesthas_keyR2t TimeoutError(R R&RVtoptionstargstspecified_homedirtotvthomedirR]tdefaultstkt servers_fntcommandtdispatch((s0/usr/lib/python2.6/site-packages/pyzor/client.pytruns|       (     !    cCsQ|dj otiid|ntiidtidtiddS(Ns%s s usage: %s [-d] [--homedir dir] command [cmd_opts] command is one of: check, report, discover, ping, digest, predigest, genkey Data is read on standard input (stdin). ii(R/R`RgRhRaRy(R ts((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRcs   cCsyti|ddWn+tij o|id|dnXt|ii}x$|iD]}|i||fqbW|iS(Nits)%s does not take any non-option argumentsi( R_RbRct ClientRunnerRTRRURtall_ok(R Rtrunnertserver((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs c Csy&ti|dddg\}}Wn+tij o|id|dnXd}x+|D]#\}}|djo d}qaqaWt|ii}xZtti|i |D]@}|pqnx)|i D]} |i | || f} qWqWt S(NiRtmboxs)%s does not take any non-option argumentsiRs--mbox( R_RbRctInfoClientRunnerRTRtget_input_handlerR`tstdint digest_specRURtTrue( R RR~targs2tdo_mboxRRRRRtresponse((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs$&    c Csy&ti|dddg\}}Wn+tij o|id|dnXd}x+|D]#\}}|djo d}qaqaWt|ii}xXtti|i |D]>}|pqnx'|i D]} |i | || fqWqW|i o|i S(NiRRs)%s does not take any non-option argumentsiRs--mbox(R_RbRctCheckClientRunnerRTRRR`RRRURt found_hitt whitelisted( R RR~RRRRRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s$&   c Csy&ti|dddg\}}Wn+tij o|id|dnXd}x+|D]#\}}|djo d}qaqaWt}xWtti|i|D]=}|pqn|i||i|i i p t }qqW|S(NiRRs)%s does not take any non-option argumentsiRs--mbox( R_RbRcRRR`RRt send_digestRTRtFalse( R RR~RRRRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR"s$&  cCs_|djodSt|tt|}x*|iD]}|i||||fq5W|iS(s*digest can be none; if so, nothing is sentN(R/t typecheckt DataDigestRRURR(R RRt client_methodRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR:s    c Csy&ti|dddg\}}Wn+tij o|id|dnXd}x+|D]#\}}|djo d}qaqaWt}xWtti|i|D]=}|pqn|i||i|i i p t }qqW|S(NiRRs)%s does not take any non-option argumentsiRs--mbox( R_RbRcRRR`RRRRTRR( R RR~RRRRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRHs$&  c Csy&ti|dddg\}}Wn+tij o|id|dnXd}x+|D]#\}}|djo d}qaqaWxBtti|i|D](}|pqntiid|qWt S( NiRRs)%s does not take any non-option argumentsiRs--mboxs%s ( R_RbRcRR`RRtstdoutRhR(R RR~RRRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR`s&  c s|yti|ddWn+tij oid|dnXdfd}tthtd6|tS(NiRs)%s does not take any non-option argumentsiRcs'x ttiiD]}qWdS(N(RR`RR(R(RR (s0/usr/lib/python2.6/site-packages/pyzor/client.pytloop|st DataDigester(R_RbRctmodglobal_applytglobalstPrintingDataDigesterR(R RR((R Rs0/usr/lib/python2.6/site-packages/pyzor/client.pytprint_digestedtsc Cs1yti|ddWn+tij o|id|dnXddk}|idd}|idd}||jotiid dS~tt}|i t i }~t i |}t i }|i |i|i |tiid tiid |i|iftS( NiRs)%s does not take any non-option argumentsiitpromptsEnter passphrase: sEnter passphrase again: sPasswords do not match. s salt,key: s%s,%s (R_RbRctgetpassR`RgRhRftrandfileRQtshat digest_sizetnewtupdateRRt hexdigestR( R RRtp1tp2tsaltfiletsaltt salt_digestt pass_digest((s0/usr/lib/python2.6/site-packages/pyzor/client.pytgenkeys,     cCsTt}|it|t|djo!tiidtidn|S(Nis8No servers available! Maybe try the 'discover' command i(RDRQRfRdR`RgRhRy(RRU((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRws  cCsQt}tii|o1x.tt|D]\}}|||s\sRcCsd|_d|_d|_||_|i|\}}t|djodSti|_ t||i jo|i |n|i |||t |i i|_|idj pt|idj ptdS(Ni(R/RRRRtget_line_offsetsRdRRRtatomic_num_linest handle_atomict handle_piecedRRtAssertionError(R tfpRRtoffsets((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s    cCsFt|_y/|idx|D]}|i|q WWnnXdS(swe digest everythingiN(RRtseekt handle_line(R RRO((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs  c Cst|_x|D]\}}d|jo djnpt|t|t|d}|i|x9t|D]+}|i}|pPn|i|qyWqWdS(NiidgY@( RRRtintRdRtrangetreadlineR( R RRRt perc_offsettlengthtoffsettiRO((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s  %   c Cs|io|i}d}nd}ti}g}x|D]}|i|}|i|}|o|i|nd}|iot|}n/|o'|d7}t|}|i |n||7}q?W|ip |}n||fS(sreturn tuple of (fp2, line offsets) If we are not seekable, fp will be copied into a tempfile, and fp2 is hence re-usable. If we are not seekable, we also normalize the lines while copying them into the tempfile. is N( RttellR/ttempfilet TemporaryFilet normalizetshould_handle_lineRJRdRh( R Rt cur_offsettnewfpRROtnormt should_handletmoved((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs.          cCs:|io|i|}n |i}|i|dS(N(RRtrstript_really_handle_buf(R ROtbuf((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRPs  cCs|ii|dS(N(RR(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR[scCs*|idjo tdnt|iS(Nsdigest not calculated yet(RR/t RuntimeErrortbool(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt is_atomic^s cCs|iS(N(R(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt get_digestcscCs||i}|}|ii||}|ii||}|ii||}|ii||}|iid|}|S(NR(tunwanted_txt_replt longstr_ptrntsubt email_ptrnturl_ptrnt html_tag_ptrntws_ptrn(R Rtreplts2((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRfs cCst|it|jS(N(Rtmin_line_lengthRd(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRss(RARBt__doc__RCRRRHtcompileRt IGNORECASERRRRRRR RRRRRRRRt classmethodR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs.     2     RcBseZdZdZRS(s5extends DataDigester: prints out what we're digestingcCs.tiid|tt|i|dS(Ns%s (R`RRhtsuperRR(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR|s(RARBRR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRysRcCsy|djo,tdtt|||ifS|djot||S|djo t|StddS(svReturn an object that can be iterated over to get all the digests from fp according to spec. mbox is a booleanRcSs |dj S(N(R/(tx((s0/usr/lib/python2.6/site-packages/pyzor/client.pytsRtdigestssunknown input styleN(tfilterRtrfc822BodyCleanerRtMailboxDigestertJustDigestsIteratort ValueError(RRtstyleR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs      RcBs#eZdgZdZdZRS(RcCs ||_dS(N(R(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR scCs'ti}|p tn|iS(N(RRt StopIterationR(R tl((s0/usr/lib/python2.6/site-packages/pyzor/client.pytnexts  (RARBRCR R(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs  RcBs,eZdddgZedZdZRS(RRRcCs7ddk}|i|t|_||_||_dS(Ni(tmailboxtPortableUnixMailboxRRRR(R RRRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s     cCsoy|ii}Wn#tj odGHdGHd}nX|djo tnt||id|iiS(Ns2Error: Please feed mailbox files in on stdin, i.e.s& pyzor digest --mbox < my_mbox_fileR( RRtIOErrorR/RRRRR(R tnext_msg((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs   (RARBRCRR R(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs RcBs5eZddddgZdZdZdZRS(Rt multifiletcurfilettypec Csti|dd}|ipd|_d|_d|_|id o@|idjo0|idjo |i djo d|_n|idjo d|_n|idjo$|i }|i |_|djo|d jo d }nd dk }t i |_yti|i |i|Wn|ij o5}tiid |i|fti|_nEtj o}|i |_n%tij o}|i |_nXy|iidWqqXqn|id joyZti|i dt|_|ii|id|ii|i|i|_Wqtttifj o|i |_d|_qXn|idjp|id jo|idj ptnP|idjo(y|idWnnX||_n|idjptdS(NRittexttFromtplaint7bittbinaryRt8bitst8bitis%s: %s t multiparttboundary( t mimetoolstMessaget getmaintypeRR/RRR|tsubtypet getencodingRtbinasciiRRtdecodetErrorR`RgRht __class__R7R8RRt MultiFileRtpushtgetparamRt TypeErrortAttributeErrorR(R RRtencodingRte((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s`  !#             cCsd}yt|idjo|ii}n|idjo=| o5|iio%|i|i|_|i}nWntttifj onX|S(NRRR R(stexts multipartsbinary( RRRRRRRRR(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs(cCscy|i}Wn;tij o,}tiid|i|ftnX|p tn|S(Ns%s: %s (RRRR`RgRhRR(R RR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs  (RARBRCR RR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs D RcBs;eZddgZdZdZddZdZRS(troutineRcCs||_|idS(N(Rtsetup(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s cCs t|_dS(N(RR(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR$scCs|djo h}ndt|}d}y)t|i||}|i||WnKtttfj o6}ti i |d|i i |ft |_nXdS(Ns%s s%s: %s (R/R R2Rthandle_responset CommErrorR=RR`RgRhRRARR(R RR4R5tmessageRR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR's  cCsB|ip t|_ntii|t|iddS(s)mesaage is a string we've built up so fars N(tis_okRRR`RRhR t head_tuple(R RR!((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR5s   N(RARBRCR RR/RR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs     RcBs,eZddgZdZdZdZRS(RRicCs)t|_t|_tt|idS(N(RRRRRR(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyREs  cCs|dt|i7}|iot|d}|djod}t|_n+t|d}|djo t|_n|d||f7}tii |dnti i |dS(Ns%s sWL-CountitCounts%d %ds ( R R#R"RRRRR`RRhRg(R RR!twl_counttcount((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRJs     (RARBRCtwl_count_clearsRR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR>s  RcBseZdZRS(cCs|dt|i7}|iot|d}|d|7}|djoxdD]}|i|owt||}|d jo d }nti|}|djo|d t|d 7}n|d ||f7}qYqYWntii |nti i |dS(Ns%s R$s Count: %d itEnteredtUpdateds WL-Entereds WL-UpdateditNevers WhiteList Count: %d sWL-Counts %s: %s (R(R)s WL-Entereds WL-Updated( R R#R"RR|ttimetctimeR`RRhRg(R RR!R&tftvaltstringed((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR_s$      (RARBR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR^stAccountcBsDeZdZdZdZeeZdZeeZRS(cCs|idS(N(tvalidate(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR scCs't|itit|itdS(N(RR#RKtUsernameR$tKeystuff(R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR1scCs|dS(Ni((R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR#scCs|dS(Ni((R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR$s(RARBR R1R#tpropertyR$(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR0s      R3cBsteZdZdZdZdZeeZdZeeZdZ e e Z dZ e e Z RS(sVtuple of (salt, key). Each is a long. One or the other may be None, but not both.cCs|idS(N(R1(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR scCs}|ddjo tdnx8|D]0}t|tp |djp tdq%q%Wtd|p tdndS(Nisno key informations!Keystuff must be long's or None'scSs |dj S(N(R/(R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRsskeystuff can't be all None's(R/Rt isinstancetlongR(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR1s cCsE|id}t|djo tdn|t|i|S(Nt,is]invalid number of parts for keystuff; perhaps you forgot comma at beginning for salt divider?(tsplitRdRtmapt hex_to_long(R Rtparts((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt from_hexstrs cCs|djodSt|dS(s)Allows the argument to be an empty stringRiN(R/R6(th((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR:s cCs|dS(Ni((R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRscCs|dS(Ni((R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR%s( RARBRR R1R<RR:RRR4R%(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR3s         RcBs;eZdZeeiedfZdZ dZ RS(sVKey is pyzor.Address, value is Account When getting, defaults to anonymous_accountlcCs:t|tit|ttt|i||dS(N(RRKRLR0RRt __setitem__(R RR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR>s cCs8ytt|i|SWntj o |iSXdS(N(RRt __getitem__R=tanonymous_account(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR?sN(Nl( RARBRR0RKtanonymous_userR3R/R@R>R?(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs   R[cBs8eZdZdddgZdZdZdZRS(spIteration gives a tuple of (Address, Account) Layout of file is: host : port ; username : keystuff RtlinenoRcCs%||_d|_ti|_dS(Ni(RRBRKRR(R R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR s  cCs|S(N((R ((s0/usr/lib/python2.6/site-packages/pyzor/client.pyt__iter__sc Cs9x2|ii}|id7_|p tn|i}| p|idoqn|id}td|}t|djo|i i d|iqnyNt i |dt |dftt|dti|d ffSWqtj o&}|i i d |i|fqXqdS( NiREt:cSs |iS((RF(R((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRsis4account file: invalid line %d: wrong number of partsiiis!account file: invalid line %d: %s(RRRBRRFRGR8R9RdRR<RKRLRR0R2R3R<R(R RPROtfieldsR((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRs*      (RARBRRCR RCR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyR[s   cCstidS(N(RSR(((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRscCs tdS(N(R}(tsignumtframe((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRscCs5ddk}t|di|i|idS(Nitwb(turllib2RfRhturlopenRQ(turltoutfileRI((s0/usr/lib/python2.6/site-packages/pyzor/client.pyRvs (*RRHRitos.pathRRR7R_RR RRRKt __author__t __version__t __revision__RtobjectRtlistRDRSRRRRt BasicIteratorRRRRRRttupleR0R3tdictRR[RRRv(((s0/usr/lib/python2.6/site-packages/pyzor/client.pytsJ               U M  c! !,,